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
Jul 31, 2009, 09:27 UTC
Message-ID
<m3ljm5ryar.fsf@localhost.localdomain>
In-Reply-To
<20090731081723.GE29909@nalle>
Mikko Rapeli <mikko.rapeli@iki.fi> writes:
Show 7 quoted lines
> How do I embed a hash, tag or branch name into source code managed by
> git?
> 
> I've tried searching the net, git manuals etc but haven't found a
> replacement for the old '$Id: $' strings from svn. What I need is a way to
> map compiled binaries and flash images to git tree heads, tags and
> branches.

You can embed SHA-1 of a _file contents_ (blob) using '$Id: $' keyword with `ident` attribute - see gitattributes manpage.

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.

If you really, really, really need it, you can embed tag or branch name into source code using `filter` attribute and custom clean/smudge filters to do keyword un-expansion and keyword expansion. But please think twice about what you want to achive with keyword expansion, and whether keyword expansion is a best solution...

-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Mikko RapeliNext: Mikko Rapeli
Message 2 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.