Fix wrong commit message(s)
  • Updated on 16 Jul 2019
  • 1 minute to read
  • Contributors
  • Share
  • Dark
    Light

Fix wrong commit message(s)

  • Share
  • Dark
    Light

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 

3x-e644d93-Screen_Shot_2018-12-25_at_16.42.10.png

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.

3x-1798767-Screen_Shot_2018-12-25_at_16.46.22.png

3. Save and close the text editor

Vim users cheatsheet :

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?