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?

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top