I need to modify commit messages in post-receive hook (add bug tracking id). Is there a graceful way to do it or do I have to script "git rebase -i" stuff?
-
Possibly related: http://stackoverflow.com/questions/5393178/get-commit-message-in-git-hook – 1615903 Apr 23 '13 at 08:58
-
Scarcely related. I need to modify the comment in an automatic way, not just obtain it. – Ivan Apr 23 '13 at 09:55
-
Sorry, meant this one: http://stackoverflow.com/questions/5823772/append-ticket-number-using-git-commit-hooks – 1615903 Apr 23 '13 at 10:05
-
This is not a duplicate. It is specific to the post-receive hook... – uesports135 Jul 15 '16 at 12:16
2 Answers
You can't modify the commit message (or any other part of the commit) as the commit-ID is a cryptographic checksum of the contents of the commit: changing any part of the commit changes the checksum, which means it's not the same commit anymore. You can make a new, different commit (similar to rebase -i
), or you can use notes, as already described.
Your best bet is generally to get the comment adjusted before making the commit in the first place. Failing that, notes are designed to allow you to attach data after the fact. Making a new commit from the old one can be made to work, but will be annoying: the developer who pushes the commit will have to obtain the new commit created by the post-receive hook.

- 448,244
- 59
- 642
- 775
You have the possibility to add a note to your commit via git-notes. It will therefore not modify your commit. Nevertheless, it will not change your git commit message either. https://www.kernel.org/pub/software/scm/git/docs/git-notes.html

- 171
- 6
-
Thanks but I need to modify the comment (replace a template pattern within it). – Ivan Apr 23 '13 at 10:48