Change last commit message without making new changes

My ideal workflow will consist of the following steps

  • edit the code
  • compilation
  • git commit -a -m commit message
  • run new binaries, tests, etc. (may take 10+ minutes)
  • start new changes while executables are still running
  • when step # 4 is finished, edit the commit message from step # 3, without entering the changes you made in step 5 , adding, say, “FOO test failed”

I cannot use git commit -a --amend -m "new commit message" because it also commits new changes. I'm not sure I want to work with staging or branching. I would just like to edit the commit message without any new changes. Is it possible?

+4
source share
3 answers

There is no need to store or do anything else.

git commit --amend -m 'Your new message.'

will not make any new changes (note the absence of the -a flag), provided that you have not explicitly added them to the index (for example, using git add ).

+12
source

Just:

 $ git stash $ git commit --amend -m "Your Modified Message" $ git stash apply 
+4
source

You can also use:

 git rebase -i HEAD^ 

This will open your text editor and allow you to change the last message. You need to replace the word pick at the beginning of the line with reword , save the file and exit. After that, a new text editor will open that allows you to change the commit message.

This sounds a bit more than the proposed git commit --amend , but it also works for older commits. Therefore, if you find that you want to change two messages in the last ten commits, you can run git rebase -i HEAD~10 and change the word pick to reword and change both of these messages.

Just for the curious: -i means interactive reboot.

+2
source

All Articles