I have a problem, i like to refer to other commits from within commit messages, which i do with the SHA ID, but i also like to change a previous commit from time to time. When i change a commit, the SHA ID changes, any ideas? is there another way to uniquely refer to a commit? thanks
Share
There’s no automatic way to address this. What you probably want to do is finalize commits at some point (i.e. when merged to master and pushed) and at that point confirm that all SHA1s are pointing to the right place.
One way you could check yourself would be to grep commit messages for SHA1s (e.g.
git log --grep='[0-9a-f]{7}), and check whether the given SHA1 represents a commit which is an ancestor of the commit whose message mentions it. You could trigger that check from a hook, too. Exactly which hook depends on your workflow; I could see pre-commit or post-merge being possibilities. For single-commit verification (like pre-commit), you wouldn’t actually have to grep the logs, just the current commit message. For a merge, you’d want to grep the logs of the commits being merged.