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

Re: Something like $Id$, $Revision$ or $Date$?

From
Jakub Narebski <jnareb@gmail.com>
Date
Nov 10, 2008, 15:59 UTC
Message-ID
<m3iqqvefmo.fsf@localhost.localdomain>
In-Reply-To
<87ljvsjuq7.fsf@erwin.mina86.com>
Michal Nazarewicz <mina86@tlen.pl> writes:
Show 15 quoted lines
> Hello,
> 
> as probably many of you know CVS supported some magic tags which were
> replaced in committed files to a predefined value.  For instance, if
> there was a "$Revision$" string in a file it would get replaced with
> "$Revision: x.y $" (or "$Revision: x.y.z.w $" and so on) where "x.y" is
> file's revision number.
> 
> Now, what I need is such feature in GIT.  Upon committing I would like
> some magic string (say "$Date$") to be replaced with some value
> identifying uniquely given version of a file (a date of the commit would
> be sufficient).
> 
> I tried using some hooks for it but couldn't came up with anything that
> would actually work.

Well, there is `ident` attribute which you can set in .gitattributes file which would make git do $Id$ keyword expansion. However the $Id$ git uses is not something you are familiar with: it is 40-character hexadecimal blob object name. With it you can find (try to find) relevant commit.

The reason why git doesn't support keywords like $Revision$ or $Date$ is performance: the $Revision$ and $Date$ are keywords related to _commit_ data, not blob data. You can have the same contents of the file in two different branches, thus two different commits, thus two different $Revision$ or $Date$. If contents of file didn't change between branches, git doesn't touch the file, which results in much faster branch switching, for example (and also faster committing).

What you can do is one of the following things:
1. You can try to use either hooks (post-commit, post-update I think)
   or smudge / clean filters (via gitattributes) to do keyword
   expansion. This hits performance, and you probably would have the
   problems CVS ad with keyword expansion.
2. You can use `export-subst` gitattribute and make git-archive do
   keyword expansion, which can include things like '$Format:%aD$'
   for commit date (equivalent of $Date:$?).
3. You can run some local equivalent of GIT-VERSION-GEN script git
   and Linux kernel uses, and make your build system (Makefile)
   replace '@@VERSION@@' or '++VERSION++' keywords / placeholders
   as part of compiling process.
HTH
-- 
Jakub Narębski
Poland
ShadeHawk on #git
Previous: Francis GaliegueNext: Michal Nazarewicz
Message 11 of 18 in “Something like $Id$, $Revision$ or $Date$?”
  1. Michal NazarewiczNov 10, 2008
  2. Sverre RabbelierNov 10, 2008
  3. Michal NazarewiczNov 10, 2008
  4. dhruvaNov 10, 2008
  5. Michal NazarewiczNov 10, 2008
  6. Johannes SixtNov 10, 2008
  7. Johannes SchindelinNov 10, 2008
  8. dhruvaNov 10, 2008
  9. Michal NazarewiczNov 10, 2008
  10. Francis GaliegueNov 10, 2008
  11. Jakub NarebskiNov 10, 2008
  12. Michal NazarewiczNov 10, 2008
  13. Jakub NarebskiNov 10, 2008
  14. Michal NazarewiczNov 10, 2008
  15. Jakub NarebskiNov 10, 2008
  16. Francis GaliegueNov 10, 2008
  17. Jakub NarebskiNov 10, 2008
  18. Brian GernhardtNov 10, 2008

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.