Search code examples
gitident

Update ident string after checkin


I have enabled the expansion of $Id:$ via ident in the .gitattributes file. This allows me to quickly identify whether the file is outdated when someone else checked out my repository and installed it from there.

Now, I also sync the contents of my own Git repository to other (non-development, i.e. without Git) systems. The trouble is that the keyword expansion only happens on checkout, but my workflow is commit -> push -> sync, so the synced copies contain outdated Ids.

How can I easily force an update of the Ids after a local commit? (Bonus points for doing this automatically after any commit!)

A simple git checkout doesn't work (also not with --force), probably because the file contents haven't changed. Neither does git checkout-index --force. I only managed to accomplish this via either local modification (cumbersome, need to know the modified files):

$ echo "modified" >> file
$ git checkout file

or by temporarily checking out the previous commit:

$ git checkout HEAD^
$ git checkout HEAD@{1}

Solution

  • This can be done via a post-commit hook. I've automated the setup via a script, maintained as part of my git-extensions repository:

    $ git-ident-update --help
    Update the expansion of $Id$ to $Id:...$ via ident in the .gitattributes
    after a commit.
    To do this automatically in the future, invoke with --install.
    Usage: git-ident-update [--install|--uninstall|--status|--set [<path>[ <path> ...]]] [-?|-h|--help]