git: What is the "right way" to fix an incorrect pushed commit message

860 views Asked by At

I wrote an incorrect commit message, and I've pushed it to the remote. There are no small number of questions that already deal with this:

are just a couple. But they all seem to terminate with git push --force, and the additional warning about why this is a bad idea - it edits the history, which means that everyone else who uses the repository suffers when they try to pull. They don't seem to say what the "right" thing to do is.

So what's the recommended or "correct" way to deal with this situation? I thought I could add an extra message with git commit --allow-empty, but supposedly there is "rarely a good reason to do this". Is --allow-empty indeed the right way to fix things? If not, what is the right way?

Note: Doing things the "right way" can involve "admitting I screwed up". As an example of what I'm looking for, the git tag man page has a discussion on retagging pushed tags. It clearly discusses methods to re-tag incorrectly tagged commits, giving both a recommended course of action and a --force-ish way of doing things.

1

There are 1 answers

2
David Deutsch On BEST ANSWER

One thing you can do is to add a note to the commit, e.g. git notes add -m "Here is my note" head~1. This will then show up in the git log without actually changing the commit. Another alternative is to add an annotated tagto the commit, e.g. git tag -a tag-summary -m "Here are the tag details" head~1. I prefer the tag approach, as tags show up in the log view of most tools, whereas notes do not (though they do show up in git log).