git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to embed a hash, tag or branch name?

From
Jakub Narebski <jnareb@gmail.com>
Date
Aug 1, 2009, 13:13 UTC
Message-ID
<200908011513.13016.jnareb@gmail.com>
In-Reply-To
<4A743735.9020806@dirk.my1.cc>
On Sat, 1 August 2009, Dirk Süsserott wrote:
> Am 31.07.2009 11:52 schrieb Mikko Rapeli:
>> On Fri, Jul 31, 2009 at 02:27:50AM -0700, Jakub Narebski wrote:
Show 16 quoted lines
>>> You can embed SHA-1 of a _file contents_ (blob) using '$Id: $' keyword
>>> with `ident` attribute - see gitattributes manpage.
>> 
>> Great, thanks!
>> 
>>> The correct solution of embedding version number is to do it at 
>>> _build time_, using e.g. script similar to GIT-VERSION-GEN used by
>>> Git itself and by Linux kernel.  It helps if you tag your releases.
>> 
> 
> Hi Mikko,
> 
> I don't know whether you want to use the "ident" command on your final
> binary. With Git, that's pointless, as all source files will have the
> same $Id$. So it's perfectly sufficient to have only ONE file enriched
> with Git's SHA1.

You are wrong. In Git $Id$ / $Id: $ expands to SHA-1 id of _blob_ (i.e. of file *contents*), not SHA-1 id of a commit. This way when switching branches or rewinding branch using git-reset we don't have to pay huge performance penalty because of `ident`, as we would have because every file would have to be changed if $Id$ was about commit id (or if there was $Revision$ or $Author$ implemented).

> Suggestion: During build time, compile (and link in) a file (e.g.
> version.c) with "-DVERSION=\"$(git describe)\"". My version.c looks like
> this:

GIT-VERSION-GEN and various tricks in Makefile do just that, not only for compiled parts, but also for scripts.

[...]
-- 
Jakub Narebski
Poland
Previous: Dirk SüsserottNext: Dirk Süsserott
Message 5 of 6 in “How to embed a hash, tag or branch name?”
  1. Mikko RapeliJul 31, 2009
  2. Jakub NarebskiJul 31, 2009
  3. Mikko RapeliJul 31, 2009
  4. Dirk SüsserottAug 1, 2009
  5. Jakub NarebskiAug 1, 2009
  6. Dirk SüsserottAug 1, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.