DEV Community

Mike Moore
Mike Moore

Posted on • Originally published at miketmoore.com on

Git Commit Amend

I want to start writing regularly again so I thought I'd share one of my favorite git commands:

git commit --amend --no-edit
Enter fullscreen mode Exit fullscreen mode

I use this command to combine just added changes into the last commit I made.

Here is a scenario:

Let's say I have just edited a file and already commited it, but then I realize I made a typo before I push my changes. I can edit the file, add the change (stage it), and then run git commit --amend --no-edit. This will put my typo fix into the latest commit and replace that commit's hash with a new hash. This is usually referred to as "rewriting history" in git. Now, I can push my change up as one commit, instead of two.

Here is what the official docs say about the --amend option:

Replace the tip of the current branch by creating a new commit.

https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---amend

Top comments (0)