Amend to that

Changing the last commit is a pretty common use case in Git.

Whether you forgot to add a file or simply want to revise the commit message, you will probably use the --amend flag:

$ git commit --amend

It adds the staged changes to the previous commit and prompts your default editor to update the commit message.

If you only wanna modify the commit message use the -m option:

$ git commit --amend -m "Boosted Commit Message"

But in many cases, we want to change the last commit without editing the commit message.

Today I Learned how to do exactly that, just add the --no-edit flag:

$ git commit --amend --no-edit

No popup editor and two seconds saved.

git commit amend

Note

The truth is, amending a commit actually replaces it entirely, resulting in a new commit with its own ref.

Think twice before you do that when working on a commit shared with others, as it may cause merge conflicts.

comments powered by Disqus