On Saturday, October 27, 2012 3:44:02 PM UTC+2, Philipp Kraus wrote:

> Hello,
> I would like to push a version string to a file within the Git repo, like 
> a version number, but not with an incremented value.
> I would like to put into the file the branch / tag name and the date of 
> the head eg
> On the master branch within the file should be written: master 2012-10-27
> The value on the master should be changed on each commit
> If a new branch is created the value should be: branchname <date of the 
> latest commit>
> On a tag creation the tag name and date should be added on which the tag 
> is created.
> I don't know how to do this, because I have found in the documentation 
> that Git supports
> clients and server hook (I'm comming from SVN), so I don't know which type 
> of hook is the
> best choice. IMHO it should be a server-side hook. 

This reminds me of a similar but related question: How can we get SVN's 
keyword substitution in Git.

The short answer is: you can't. But when you think about it, this file you 
want to create is actually just duplicating information which exists 
elsewhere. The right way to go about it is to find some step in your 
build/deployment mechanism, and create this file on the fly. We build our 
products using Maven and Gradle, and both these build-tools have places 
where we can hook in and generate a version.txt file with interesting 
information from Git.

Another way is to create it on checkout, as suggested in the git-scm.com 

>From http://git-scm.com/book/ch7-2.html:

SVN- or CVS-style keyword expansion is often requested by developers used 
to those systems. The main problem with this in Git is that you can’t 
modify a file with information about the commit after you’ve committed, 
because Git checksums the file first. However, you can inject text into a 
file when it’s checked out and remove it again before it’s added to a 
commit. Git attributes offers you two ways to do this.[...]

Have a read through that chapter. You may find a technique that works for 

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To view this discussion on the web visit 
To post to this group, send email to git-users@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to