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.
Written by Josh Buhler
Related protips
2 Responses
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/24935/10534_128567884189_828694189_2287781_3877042_n.jpg)
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.
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/50489/8c4b4a99d5794c95f52c58a2bf8e1710.jpeg)
You should not copy-paste the commit message or retype it with amend. You just save the file and exit from commit message editor.