Last Updated: February 25, 2016
· joshbuhler

Amend a commit, keeping the same commit message

There are plenty of times where I commit something in Git, then realize that I forgot to add one file. It's pretty easy to amend a commit to add those few missed changes, but 99% of the time, I want to keep the commit message the same. Rather than retype the last commit message, or copy/paste it while amending, just use the following command:

git commit --amend -C HEAD

Assuming you've staged the appropriate files you'd like to amend the commit with, this will do the trick. The -C HEAD portion tells Git that you want to use the comments from the last commit message.

Of course, if you want to edit the commit message, just leave out the -C HEAD, and after running git commit --amend, Git will open up your editor and allow you to edit the last commit message instead.

2 Responses
Add your response


If you're using -m when committing it's probably simpler most of the time to just press up on the keyboard and add --amend at the end.

over 1 year ago ·

You should not copy-paste the commit message or retype it with amend. You just save the file and exit from commit message editor.

over 1 year ago ·