Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

  • How to modify existing, unpushed commits?
  • Accidentally pushed commit: change git commit message

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.

like image 915
Praveen Avatar asked Oct 26 '25 10:10

Praveen


1 Answers

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

like image 61
David Deutsch Avatar answered Oct 28 '25 00:10

David Deutsch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!