Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9189107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:10:15+00:00 2026-06-17T20:10:15+00:00

I am trying to create a pre-commit hook for git that edits the comments

  • 0

I am trying to create a pre-commit hook for git that edits the comments at the top of each of my .h and .m files. I would like to change the header comments added by x-code to include the app version and license information. This would be helpful when changing to a new version.

This is the text that is automatically inserted when I create a file in x-code:

//
//  myFile.h
//  myApp 
//
//  Created by Developer on 11/13/12.
//  Copyright (c) 2012 myCompany LLC. All rights reserved.
//

I would like the hook to change it to this:

/*

myFile.h
myApp
Version: 1.0

myApp is free software: you can redistribute it and/or modify it under the terms 
of the GNU General Public License as published by the Free Software Foundation,
either version 2 of the License, or (at your option) any later version.

myApp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with myApp.
If not, see <http://www.gnu.org/licenses/>

Copyright 2012 myCompany. All rights reserved.


This notice may not be removed from this file.

*/

I was thinking that I would have a text file with the header text I want to change. Or detect when the app version number changes. When this file is updated with a new version number and git I do a git commit, then it will update all the other files with the new version and change any new files to have the correct header text. This seems like it might be useful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:10:16+00:00Added an answer on June 17, 2026 at 8:10 pm

    I’ve done similar before using the equivalent of a perl inplace-edit ‘-i’ but using a perl script instead of just on the command line as the data is bigger.

    I’ve done the following which should suite your needs, given some tweaking and testing :D.

    The new source header is defined in the __DATA__ section of the perl script.

    There’s an illustration of how you can pass the VERSION and COPY_YEAR via environment variables.

    It’s a while since I’ve done some serious perl but it works on my testcases, it creates backups although I’d suggest you back up your files first.

    I hope it helps in some way.

    Example usage:

    $ perl add_header *.h *.m 
    

    Script:

    use strict;
    my $extension = '.orig';
    local $/ = undef; # slurp
    my $oldargv = undef;
    
    my $replacement = <DATA>;
    $replacement =~ s/{VERSION}/$ENV{VERSION} or '1.0.alpha'/e;
    $replacement =~ s/{COPY_YEAR}/$ENV{COPY_YEAR} or '2013'/e;
    
    LINE: while (<>) {
        if ( $ARGV ne $oldargv) {
            my $backup = undef;
            if ($extension !~ /\*/) {
                $backup = $ARGV . $extension;
            }
            else {
                 ($backup = $extension) =~ s/\*/$ARGV/;
            }
            rename($ARGV, $backup);
            open(ARGVOUT, ">$ARGV");
            select(ARGVOUT);
            my $oldargv = $ARGV;
        }
        s!^//.*Copy.*?//$!$replacement!sm; # THE BUSINESS END.
    }
    continue {
        print;
    }
    select(STDOUT);
    __DATA__
    /**
     *  My New Header...
     *  Version info {VERSION} ]}
     *  made {COPY_YEAR}
     */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an svn pre-commit hook, but can't get my regular expression
I'm trying to create a templated composite control that would work in a similar
I'm trying to create a top navigation in Umbraco 4.10.1 that is based upon
I am trying to create a subversion pre-lock hook on windows. However I have
I'm trying to create a Mercurial hook that runs when the commits are being
I'm trying to create a WordPress plugin, and I would like to have jQuery
I am trying to create a simple blog that has code inclosed in <pre>
I have created a little pre-commit hook in python. This hook works like a
I'm trying to pre-populate create defect popup and I'm not clear on what key/values
I'm trying to create a shell like environment, where a user is presented with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.