I recently $ git add .
some changes I made to one of my repositories followed by $ git commit -m'INcorrect commit message'
.
I decided to change the incorrect commit message to 'Correct commit message' using:
$ git commit --amend
The instructions I followed to do this can be found here: https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages
I use Atom, so Atom opens with 'INcorrect commit message' displayed, which I change to 'Correct commit message' and save my changes.
After I saved the altered commit message, I did a $ git log -1
expecting to see 'Correct commit message'; however, I still see 'INcorrect commit message.'
What exactly am I doing wrong?
Note
Just prior to this, I changed my git editor from Sublime to Atom following these instructions: How do I make Git use the editor of my choice for commits?
I basically used:
$ git config --global core.editor "atom"
and
$ export GIT_EDITOR=atom
I realize now that I didn't have to do both, but I also realize this probably didn't hurt either.
There were two things that fixed this for me.
One
As @torek pointed out in his comment attached to my original post, setting the --wait argument when invoking Atom blocks git from returning from the $ git commit --amend
command. Apparently, this is necessary for git to successfully capture the altered commit message, rather than returning before the message has even been altered. Makes sense.
$ git config --global core.editor "atom --wait"
Two
Apparently, if I did not explicitly save my altered commit message (command + s on mac), it would never get saved. This I had to do in order to get the commit message to recognize my altered commit message.
This might seem pretty obvious at first; however, if I altered my commit message and clicked the close window button ('x' at the top-left of the window on mac), something strange would happen...
If I altered my commit message, close Atom using the close window button ('x'), and then subsequently execute a $ git log -1
command, the commit message would show the original unaltered commit message. Nothing strange there.
However, if I then executed another $ git commit --amend
command, Atom would open and display the altered commit message from the previous $ git commit --amend
command! This is very strange behavior if you ask me. Not being a git guru, lets just say this didn't clear up any confusion for me.
Bottom line
Append the --wait argument ($ git config --global core.editor "atom --wait"
), and explicitly save your altered commit message in Atom (command + s on mac) when performing a $ git commit --amend
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With