{"thread":{"id":"22249","subject":"Stamp Git commit id into file during build process","startedAt":"2010-01-16T18:50:48Z","lastAt":"2010-01-16T21:27:22Z","messageCount":10,"participants":["Paul Richards","Erik Faye-Lund","Sverre Rabbelier","Jakub Narebski","Shawn O. Pearce"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"131898","messageId":"a1138db31001161050i73eade1bif968ca1256dcef2c@mail.gmail.com","threadId":"22249","inReplyTo":null,"subject":"Stamp Git commit id into file during build process","fromName":"Paul Richards","fromEmail":"paul.richards@gmail.com","sentAt":"2010-01-16T18:50:48Z","receivedAt":"2010-01-16T18:50:48Z","isPatch":false,"sender":{"key":"paul.richards@gmail.com","avatar":"https://gravatar.com/avatar/79ad1fd7cbf40f3c342e4f2586a69ecde83b3f05804639cbc709a812d47613d1?d=mp&s=160"},"body":"Hi,\nI am in the process of migrating from Subversion to Git.  One thing I\nam unsure of is how to stamp the 'version' or 'commit id' into a file\nas part of a build process.\n\nWith subversion I used the SubWCRev tool from TortoiseSVN\n(http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html).\n\nWith Git I imagine that I'd like to put a copy of the current commit\nid (either the full hash or a truncated version of that) into a file\nwhich then gets included into the program source code in some way.\n\nIs there a recommended way of doing this with git?  Perhaps with\nsomething similar to SubWCRev?\n\nCurrently I am thinking about using \"git log\", and grepping the output\nin some way so that I just get the hash.\n\nThanks in advance,\n\n\n-- \nPaul Richards\n"},{"id":"131900","messageId":"40aa078e1001161114w5a65bebbhaf43317634899925@mail.gmail.com","threadId":"22249","inReplyTo":"a1138db31001161050i73eade1bif968ca1256dcef2c@mail.gmail.com","subject":"Re: Stamp Git commit id into file during build process","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2010-01-16T19:14:44Z","receivedAt":"2010-01-16T19:14:44Z","isPatch":false,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Sat, Jan 16, 2010 at 7:50 PM, Paul Richards <paul.richards@gmail.com> wrote:\n> Hi,\n> I am in the process of migrating from Subversion to Git.  One thing I\n> am unsure of is how to stamp the 'version' or 'commit id' into a file\n> as part of a build process.\n>\n> With subversion I used the SubWCRev tool from TortoiseSVN\n> (http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html).\n>\n> With Git I imagine that I'd like to put a copy of the current commit\n> id (either the full hash or a truncated version of that) into a file\n> which then gets included into the program source code in some way.\n>\n> Is there a recommended way of doing this with git?  Perhaps with\n> something similar to SubWCRev?\n>\n> Currently I am thinking about using \"git log\", and grepping the output\n> in some way so that I just get the hash.\n>\n\nI think you are looking for \"git rev-parse HEAD\". This outputs the\nhash of HEAD as a single line on stdout. Or even better, you can use\nthe \"git describe\"-tool, which gives a nice and short description of\nthe commit relative to the most recent commit.\n\n-- \nErik \"kusma\" Faye-Lund\n"},{"id":"131901","messageId":"40aa078e1001161115r312f2e7ahbe9bab6c28b3ad2e@mail.gmail.com","threadId":"22249","inReplyTo":"40aa078e1001161114w5a65bebbhaf43317634899925@mail.gmail.com","subject":"Re: Stamp Git commit id into file during build process","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2010-01-16T19:15:51Z","receivedAt":"2010-01-16T19:15:51Z","isPatch":false,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Sat, Jan 16, 2010 at 8:14 PM, Erik Faye-Lund\n<kusmabite@googlemail.com> wrote:\n> the \"git describe\"-tool, which gives a nice and short description of\n> the commit relative to the most recent commit.\n>\n\n...by \"most recent commit\", I mean \"most recent tag\". Sorry about that.\n\n\n-- \nErik \"kusma\" Faye-Lund\n"},{"id":"131902","messageId":"fabb9a1e1001161117t6d572024yc5598be1b32ffcde@mail.gmail.com","threadId":"22249","inReplyTo":"40aa078e1001161114w5a65bebbhaf43317634899925@mail.gmail.com","subject":"Re: Stamp Git commit id into file during build process","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-01-16T19:17:07Z","receivedAt":"2010-01-16T19:17:07Z","isPatch":false,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Sat, Jan 16, 2010 at 20:14, Erik Faye-Lund <kusmabite@googlemail.com> wrote:\n> I think you are looking for \"git rev-parse HEAD\". This outputs the\n> hash of HEAD as a single line on stdout. Or even better, you can use\n> the \"git describe\"-tool, which gives a nice and short description of\n> the commit relative to the most recent commit.\n\nIt would be better to have a look at gitattributes [0] instead.\n\n[0] http://www.kernel.org/pub/software/scm/git/docs/gitattributes.html#_tt_ident_tt\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"131903","messageId":"40aa078e1001161122k48f55807y3f01fa0d38e5cc93@mail.gmail.com","threadId":"22249","inReplyTo":"fabb9a1e1001161117t6d572024yc5598be1b32ffcde@mail.gmail.com","subject":"Re: Stamp Git commit id into file during build process","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2010-01-16T19:22:38Z","receivedAt":"2010-01-16T19:22:38Z","isPatch":false,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Sat, Jan 16, 2010 at 8:17 PM, Sverre Rabbelier <srabbelier@gmail.com> wrote:\n> Heya,\n>\n> On Sat, Jan 16, 2010 at 20:14, Erik Faye-Lund <kusmabite@googlemail.com> wrote:\n>> I think you are looking for \"git rev-parse HEAD\". This outputs the\n>> hash of HEAD as a single line on stdout. Or even better, you can use\n>> the \"git describe\"-tool, which gives a nice and short description of\n>> the commit relative to the most recent commit.\n>\n> It would be better to have a look at gitattributes [0] instead.\n>\n\nSince he's looking for a replacement for SubWCRev (as opposed to\nsvn:keywords); not really.\n\n-- \nErik \"kusma\" Faye-Lund\n"},{"id":"131904","messageId":"fabb9a1e1001161129j12c79a2dq21557938d4cf973c@mail.gmail.com","threadId":"22249","inReplyTo":"40aa078e1001161122k48f55807y3f01fa0d38e5cc93@mail.gmail.com","subject":"Re: Stamp Git commit id into file during build process","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-01-16T19:29:28Z","receivedAt":"2010-01-16T19:29:28Z","isPatch":false,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Sat, Jan 16, 2010 at 20:22, Erik Faye-Lund <kusmabite@googlemail.com> wrote:\n> Since he's looking for a replacement for SubWCRev (as opposed to\n> svn:keywords); not really.\n\nI misunderstood then, since he mentioned 'git log' and you mentioned\n'git rev-parse HEAD', and I do not know what SubWCRev does.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"131905","messageId":"m3d419desd.fsf@localhost.localdomain","threadId":"22249","inReplyTo":"a1138db31001161050i73eade1bif968ca1256dcef2c@mail.gmail.com","subject":"Re: Stamp Git commit id into file during build process","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-01-16T19:35:34Z","receivedAt":"2010-01-16T19:35:34Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Paul Richards <paul.richards@gmail.com> writes:\n\n> Hi,\n> I am in the process of migrating from Subversion to Git.  One thing I\n> am unsure of is how to stamp the 'version' or 'commit id' into a file\n> as part of a build process.\n> \n> With subversion I used the SubWCRev tool from TortoiseSVN\n> (http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html).\n> \n> With Git I imagine that I'd like to put a copy of the current commit\n> id (either the full hash or a truncated version of that) into a file\n> which then gets included into the program source code in some way.\n> \n> Is there a recommended way of doing this with git?  Perhaps with\n> something similar to SubWCRev?\n> \n> Currently I am thinking about using \"git log\", and grepping the output\n> in some way so that I just get the hash.\n\nNot \"git log\".\n\nTake a look how for example git project and Linux kernel use \"git describe\"\nin GIT-VERSION-GEN script, and how they use GIT-VERSION-GEN script in the\nMakefile.\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"131907","messageId":"a1138db31001161312i2c032c38tcc0fb162c61fbb35@mail.gmail.com","threadId":"22249","inReplyTo":"m3d419desd.fsf@localhost.localdomain","subject":"Re: Stamp Git commit id into file during build process","fromName":"Paul Richards","fromEmail":"paul.richards@gmail.com","sentAt":"2010-01-16T21:12:58Z","receivedAt":"2010-01-16T21:12:58Z","isPatch":false,"sender":{"key":"paul.richards@gmail.com","avatar":"https://gravatar.com/avatar/79ad1fd7cbf40f3c342e4f2586a69ecde83b3f05804639cbc709a812d47613d1?d=mp&s=160"},"body":"2010/1/16 Jakub Narebski <jnareb@gmail.com>:\n> Paul Richards <paul.richards@gmail.com> writes:\n>\n>> Hi,\n>> I am in the process of migrating from Subversion to Git.  One thing I\n>> am unsure of is how to stamp the 'version' or 'commit id' into a file\n>> as part of a build process.\n>>\n>> With subversion I used the SubWCRev tool from TortoiseSVN\n>> (http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html).\n>>\n>> With Git I imagine that I'd like to put a copy of the current commit\n>> id (either the full hash or a truncated version of that) into a file\n>> which then gets included into the program source code in some way.\n>>\n>> Is there a recommended way of doing this with git?  Perhaps with\n>> something similar to SubWCRev?\n>>\n>> Currently I am thinking about using \"git log\", and grepping the output\n>> in some way so that I just get the hash.\n>\n> Not \"git log\".\n>\n> Take a look how for example git project and Linux kernel use \"git describe\"\n> in GIT-VERSION-GEN script, and how they use GIT-VERSION-GEN script in the\n> Makefile.\n>\n\n\nThanks, it appears though that \"git describe\" does not work in Cygwin git. :(\n\n\n-- \nPaul Richards\n"},{"id":"131908","messageId":"20100116212619.GB5299@spearce.org","threadId":"22249","inReplyTo":"a1138db31001161312i2c032c38tcc0fb162c61fbb35@mail.gmail.com","subject":"Re: Stamp Git commit id into file during build process","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2010-01-16T21:26:19Z","receivedAt":"2010-01-16T21:26:19Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Paul Richards <paul.richards@gmail.com> wrote:\n> > Take a look how for example git project and Linux kernel use \"git describe\"\n> > in GIT-VERSION-GEN script, and how they use GIT-VERSION-GEN script in the\n> > Makefile.\n> \n> Thanks, it appears though that \"git describe\" does not work in Cygwin git. :(\n\nThat's a serious bug.  git describe should work fine on any system\nGit itself runs on; its written in pure C and with the exception\nof the --contains flag, doesn't rely on any external programs.\n\n-- \nShawn.\n"},{"id":"131909","messageId":"201001162227.23236.jnareb@gmail.com","threadId":"22249","inReplyTo":"a1138db31001161312i2c032c38tcc0fb162c61fbb35@mail.gmail.com","subject":"Re: Stamp Git commit id into file during build process","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-01-16T21:27:22Z","receivedAt":"2010-01-16T21:27:22Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Dnia sobota 16. stycznia 2010 22:12, Paul Richards napisał:\n> 2010/1/16 Jakub Narebski <jnareb@gmail.com>:\n>> Paul Richards <paul.richards@gmail.com> writes:\n\n>>> I am in the process of migrating from Subversion to Git.  One thing I\n>>> am unsure of is how to stamp the 'version' or 'commit id' into a file\n>>> as part of a build process.\n\n>> Take a look how for example git project and Linux kernel use \"git describe\"\n>> in GIT-VERSION-GEN script, and how they use GIT-VERSION-GEN script in the\n>> Makefile. \n> \n> Thanks, it appears though that \"git describe\" does not work in Cygwin git. :(\n\nIf you got something like\n\n  $ git describe\n  fatal: cannot describe 'a27cb622b30f18cb8510b7b3856d4029e617d95b'\n\nit means that you don't have any tags in your history.  You should tag your\nreleases (released versions) using annotated tags.\n\nAnyway you have\n\n  $ git describe --always\n  a27cb62\n\n-- \nJakub Narebski\nPoland\n"}]}