Re: Stamp Git commit id into file during build process
- From
Erik Faye-Lund <kusmabite@googlemail.com>
- Date
- Jan 16, 2010, 19:14 UTC
- Message-ID
- <40aa078e1001161114w5a65bebbhaf43317634899925@mail.gmail.com>
- In-Reply-To
- <a1138db31001161050i73eade1bif968ca1256dcef2c@mail.gmail.com>
On Sat, Jan 16, 2010 at 7:50 PM, Paul Richards <paul.richards@gmail.com> wrote:
Show 18 quoted lines
> Hi, > I am in the process of migrating from Subversion to Git. One thing I > am unsure of is how to stamp the 'version' or 'commit id' into a file > as part of a build process. > > With subversion I used the SubWCRev tool from TortoiseSVN > (http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html). > > With Git I imagine that I'd like to put a copy of the current commit > id (either the full hash or a truncated version of that) into a file > which then gets included into the program source code in some way. > > Is there a recommended way of doing this with git? Perhaps with > something similar to SubWCRev? > > Currently I am thinking about using "git log", and grepping the output > in some way so that I just get the hash. >
I think you are looking for "git rev-parse HEAD". This outputs the hash of HEAD as a single line on stdout. Or even better, you can use the "git describe"-tool, which gives a nice and short description of the commit relative to the most recent commit.
-- Erik "kusma" Faye-Lund