ProAnswers.org

Edit an incorrect commit message in git?

I did a git commit while half asleep, and wrote totally the wrong thing in the commit message,
How do I change the commit message? I have not yet pushed the commit to anyone.

git commit --amend

	Used to amend the tip of the current branch. Prepare the tree object you would want to replace the latest commit as usual (this includes the usual -i/-o and explicit paths), and the commit log editor is seeded with the commit message from the tip of the current branch. The commit you create replaces the current tip -- if it was a merge, it will have the parents of the current tip as parents -- so the current top commit is discarded.



	It is a rough equivalent for:

$ git reset --soft HEAD^
$ … do something else to come up with the right tree …
$ git commit -c ORIG_HEAD

	but can be used to amend a merge commit.
To amend previous commit make the changes you want and stage those changes, and then use

git commit --amend

to amend previous commit, and keep the same log message use

git commit --amend -C HEAD

to fix the previous commit by removing it entirely use

git reset --hard HEAD^

If you want to edit more than one commit message use

git rebase -i HEAD~COMMIT_COUNT

Do not forget to replace [b]COMMIT_COUNT[/b] with number of commits that you want to edit.



This command launches editor, mark the first commit (the one that you want to change) as "edit" instead of "pick", then save and exit your editor.



make the change you want to commit then:

git commit --amend
git rebase --continue