Questions tagged [git-amend]

Parameter of git-commit command that adds the current staging area to the last commit and allows you to (by default) edit previously used commit message or (if other options were given) reuse it or even discard it and write a new one.

New commit!

Using this option effectively creates new commit! It replaces current tip of the branch, so if you use it on anything that's NOT the tip (checking out a tag or SHA and then amending) you're effectively branching (feel free to check with logs).

It's considered a rough equivalent of

  • soft reset,
  • manual changes
  • and committing on top of ORIG_HEAD.


  1. You may also use it to amend a merge commit.
  2. Using --reset-author with --amend you also reset author and author timestamp.


git help commit

146 questions
27 answers

How to modify existing, unpushed commit messages?

I wrote the wrong thing in a commit message. How can I change the message? The commit has not been pushed yet.
Laurie Young
  • 136,234
  • 13
  • 47
  • 54
13 answers

How to undo "git commit --amend" done instead of "git commit"

I accidentally amended my previous commit. The commit should have been separate to keep history of the changes I made to a particular file. Is there a way to undo that last commit? If I do something like git reset --hard HEAD^, the first commit also…
Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155
8 answers

How to amend a commit without changing commit message (reusing the previous one)?

Is there a way to amend a commit without vi (or your $EDITOR) popping up with the option to modify your commit message, but simply reusing the previous message?
Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
21 answers

How do I push amended commit to the remote Git repository?

When I've worked a bit with my source code, I did my usual thing commit and then I pushed to a remote repository. But then I noticed I forgot to organize my imports in the source code. So I do the amend command to replace the previous commit: > git…
  • 119,724
  • 44
  • 140
  • 158
5 answers

Edit the root commit in Git?

There's ways to change the message from later commits: git commit --amend # for the most recent commit git rebase --interactive master~2 # but requires *parent* How can you change the commit message of the very first commit…
  • 11,887
  • 9
  • 47
  • 64
8 answers

Git: How to edit/reword a merge commit's message?

How do I edit or reword a merge commit's message? git commit --amend works if it's the last commit made (HEAD), but what if it comes before HEAD? git rebase -i HEAD~5 doesn't list the merge commits.
  • 121,420
  • 116
  • 450
  • 651
2 answers

git commit --amend without asking for message

From time to time I find myself commit-amending using the same message. Typically, I do: Add my changes to staging area. Do git commit --amend. Wait for the text editor to open. Save and close it (without changing the message). There is anyway to…
  • 14,356
  • 8
  • 45
  • 58
4 answers

Accidentally pushed commit: change git commit message

In my local repo I have one commit with an incorrect commit message. I've already published the incorrect commit message with git push. Now the remote repo (which is GitHub-hosted) has the incorrect commit message, too. I've already tried git commit…
  • 1,326
  • 9
  • 44
  • 62
4 answers

Git prevents pushing after amending a commit

Usually, I just run git add file git commit git push but if I amend the commit before pushing it (with git commit --amend), the next push fails with hint: Updates were rejected because the tip of your current branch is behind hint: its remote…
  • 2,522
  • 4
  • 26
  • 44
3 answers

What are the differences between 'revert', 'amend,' 'rollback', and 'undo' a commit?

To help in my knowledge of git so I can use it day to day, what is the difference between: revert amend rollback undo What are they and what do they do?
  • 755
  • 1
  • 6
  • 13
4 answers

git: change one line in file for the complete history

When I started my git repo I commited a few files as initial commit to it. Now, many commits later, I noticed that I included in those files a line with information which I do not want to publish (unlike the rest of the code). So I want to…
  • 1,172
  • 3
  • 14
  • 19
3 answers

Why does git commit --amend change the hash even if I don't make any changes?

Why does the SHA-1 hash of my latest commit change even if I don't make any changes to the commit (message, files) after running git commit --amend? Say I run the following at the command line. cd ~/Desktop mkdir test_amend cd test_amend git…
  • 60,866
  • 25
  • 183
  • 186
2 answers

Can I amend a commit made with VSCode to GitHub repo?

I learn Git and Using VSCode and just learn the commit "amend" command and now trying it on origin (GitHub). I can't find any way to do this. Do I need some external tool to do that I don't see any "push amend" from the Git menu in VSCode
  • 1,869
  • 3
  • 19
  • 48
5 answers

How to confirm changes after `git commit --amend` in Terminal?

When I write git commit --amend I get some kind of editor, where I can change the name of this commit. How to confirm and save my changes using keyboard?
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
4 answers

How does git commit --amend work, exactly?

I have seen 'git commit --amend' in detached HEAD state. The question requires the answer to be more complex than needs be. I'd like to understand just how git commit --amend works in a normal HEAD situation.
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
2 3
9 10