1

I am using keyword expansion like the one described in the book Pro Git. However, after a commit one needs to do, for example,

rm file
git checkout file

to have the correct keyword expansion in the working files (since smudge is applied only after checkout).

How do I make the keyword expansion happen automatically also after a commit?

Of course, I could use a hook for the remove/re-checkout, but that does not seem to be a nice solution. Moreover I would have to check manually, which file was commited.

Is there a more elegant way? Can I, for instance, let run the smudge of a filter automatically after commit?

Daniel Krenn
  • 251
  • 2
  • 9

2 Answers2

2

How do I make the keyword expansion happen automatically also after a commit?

You don't, that is why Git doesn't "really" support keyword expansion, as I detail in "Git equivalent of subversion's $URL$ keyword expansion".

An alternative (listed in "Git hook, modify commit files") is to use git notes to attach metadata to a commit (without modifying its SHA1).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I understand the Git philosophy on not having keyword expansion. I am using "git svn" (for writing tex-documents). I'm having keyword expansion when working with subversion directly; it is used to add a revision number to a printed out pdf for referencing. Therefore, I want to have it in my git-world as well. – Daniel Krenn Feb 24 '14 at 10:39
  • @DanielKrenn I understand. I would recommend `git notes` to add *any* information you want to a commit. – VonC Feb 24 '14 at 10:40
0

I believe a post-commit hook would indeed solve your problem.

Add the following post-commit hook:

    #!/bin/sh
    BRANCH=$( git branch | awk 'sub(/^\*[[:space:]]+/,""){print;exit}' )
    git show --name-only -z --format= |
            xargs -r0 git reset "${BRANCH:-master}" --