4

Possible Duplicate:
In Git, how can I write the current commit hash to a file in the same commit

We are stuck with the highly unfortunate but unavoidable problem of periodically having to deploy development builds of our code right out of the oven. After a while, we lose track of whose install is based on which "intermediate" untagged version of the codebase.

Does git offer some automatic macro or token embeddable in tracked files that would automatically be substituted with the latest commit hash ID from HEAD upon a 'git clone' or whatnot?

Surely there must be a way to do this; even RCS, a downright Jurassic system by the standards of today's cool kids, had a built-in version variable it could replace.

Community
  • 1
  • 1
Alex Balashov
  • 3,218
  • 4
  • 27
  • 36
  • I think there's another even older duplicate, but I couldn't find it when I wrote the answer to the one we've chosen. – Cascabel Nov 04 '10 at 13:32
  • It's also asked here: http://stackoverflow.com/questions/16524225/how-can-i-populate-the-git-commit-id-into-a-file-when-i-commit. It's newer than this question, but has some very good answers – Edward Falk Jun 30 '16 at 20:39

1 Answers1

1

As you can read in the answers to the question Ben James posted in the commnets people have concerns about placing commit hash values into files with git.

Wouldn't it be possible to use a scripted solution outside of git ? When you need to deploy a new build out of git you could create a tag, check that out and before you put together your release tar.gz or whatever you add the name of the tag to each source file. Guess there are different ways you could automate this maybe with git-archive or whatever.

Another thing that I was wondering about is that you could perhaps get away without any such tagging at all given that git organizes files based on their SHA1 hash value. So you could figure out which commit a given file belongs to based on its SHA1. Have a look at cat-file

gilligan
  • 488
  • 3
  • 15
  • 3
    It's not completely trivial to work your way back from file SHA1 to commit SHA1; the directed acyclic graph is directed the other way. See http://stackoverflow.com/questions/223678/git-which-commit-has-this-blob – Cascabel Nov 04 '10 at 13:33
  • Do it the way `git` itself does it: The Makefile creates `GIT_VERSION_FILE`, containing the complete version, and that one is included in the executables to print out with e.g. `git version`. No need to mess up the files themselves. (The whole "$Id: ..." idea made sense for RCS, which tracked individual files. Is long a leftover from better times.) – vonbrand Feb 27 '13 at 02:36