Daniel Krenn
Daniel Krenn

Reputation: 251

git keyword expansion after commit

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?

Upvotes: 1

Views: 958

Answers (2)

src committer
src committer

Reputation: 61

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}" --

Upvotes: 0

VonC
VonC

Reputation: 1324997

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).

Upvotes: 2

Related Questions