Fix wrong commit message(s)
  • 26 Mar 2020
  • 1 Minute To Read
  • Contributors
  • Share
  • Dark

Fix wrong commit message(s)

  • Share
  • Dark

1. Select the number of commit messages you need to update

Use the git rebase -i HEAD~n command to display a list of the last n commits in your default text editor.

 $ git  rebase  -i  HEAD~3  # List the last 3 commits on the current branch 


2. Replace "pick" with "reword"

For the commit messages you want to rewrite, replace "pick" with "reword" / "r".
If you are using vim as a text editor, you can enter "edit" mode by tapping "i" on your keyboard.


3. Save and close the text editor

Vim users cheatsheet (click "esc" to enter commands mode) :

Command Result
:w Save
:wq / :x Save and close file
:q Close file
:q! Close file, and and discard the changes

4. Edit each commit message

Git will now step through each of the commits and will let you rewrite the commit message.

In each resulting commit file, type the new commit message, and then save and close the file.

5. Force push your updated commit message(s)

Force-push the amended commits to your base branch

 $ git  push  --force 
Was This Article Helpful?