2

I have committed a file with message 'initial2'. Then I commit again with 'initial3'.

I execute the command git rebase -i HEAD~2

I see the vim editor with the following content.

pick 284d2e1 'initial2'                                                                                                                                       
pick e32d7f3 'initial3'

I edit 'initial2' to 'initial2aaaaa' and close the editor with :wq.

However, my message is not changed. I still see initial2.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Rahul SK
  • 350
  • 3
  • 23
  • Does this answer your question? [How to modify existing, unpushed commit messages?](https://stackoverflow.com/questions/179123/how-to-modify-existing-unpushed-commit-messages) – phd Jan 07 '20 at 13:51
  • https://stackoverflow.com/search?q=%5Bgit%5D+change+commit+message+interactive+rebase – phd Jan 07 '20 at 13:51

3 Answers3

3

The commit message in the rebase editor is purely informational. It helps the user know which commit git is talking about (since most of us don't know the hashes of their commits by hearth). Changing it here has no effect on the plan, as you noticed. Only the command (pick) and the hash (284d2e1) are actually relevant to git itself.

If you want to change the commit message then change the pick command to reword (or just r) to pick the commit and edit its commit message. The line should look like this:

reword 284d2e1 'initial2'   
Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
1
pick 284d2e1 'initial2'                                                                                                                                       
pick e32d7f3 'initial3'

when you see the above, change the first line to following (replace pick with reword)

reword 284d2e1 'initial2'    

Then try exiting with :qa.

You will be given option to edit your commit message in vm.

There you can edit and exit with :qa again. Then you will find your commit message is edited.

Narasimha
  • 759
  • 6
  • 8
0

Just to be clearer, following @Narasimha,

  1. Replace pick with reword
  2. I exit with :x
  3. Edit the same commit message again
  4. Exit with :x
Justin Lee
  • 11
  • 2
  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33462990) – user12256545 Dec 22 '22 at 12:09