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.

Trivia

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

More:

git help commit

127 questions
7659
votes
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
  • 129,506
  • 13
  • 44
  • 54
1496
votes
12 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
  • 91,561
  • 40
  • 112
  • 147
748
votes
6 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
  • 19,595
  • 12
  • 74
  • 93
723
votes
16 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…
Spoike
  • 112,352
  • 42
  • 133
  • 155
354
votes
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…
13ren
  • 10,871
  • 9
  • 44
  • 62
216
votes
8 answers

Mercurial: how to amend the last commit?

I'm looking for a counter-part of git commit --amend in Mercurial, i.e. a way to modify the commit which my working copy is linked to. I'm only interested in the last commit, not an arbitrary earlier commit. The requirements for this amend-procedure…
mstrap
  • 15,236
  • 6
  • 50
  • 77
167
votes
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.
ma11hew28
  • 106,283
  • 107
  • 420
  • 616
112
votes
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…
talles
  • 11,195
  • 8
  • 39
  • 55
66
votes
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…
jonny
  • 3,111
  • 9
  • 41
  • 57
49
votes
3 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…
kiri
  • 2,142
  • 3
  • 18
  • 42
44
votes
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…
tbolender
  • 1,112
  • 3
  • 13
  • 19
33
votes
3 answers

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

Although I use Git pretty often, I'm still a beginner. Sometimes, I make a mistake but spot it only after I have committed it. At that point, I usually have to spend a long time on the Internet looking for the command I should use to get rid of it…
gosbi
  • 536
  • 1
  • 5
  • 10
32
votes
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…
jub0bs
  • 46,795
  • 22
  • 148
  • 157
19
votes
1 answer

Why does git call me "clever" when I reword the last commit message?

I regularly run git commit --only --amend to reword the commit message of the latest commit I made. This will work irrespective of whether my working directory is clean or not. Today I noticed that when doing this, the default instructions for…
itsjeyd
  • 4,739
  • 2
  • 26
  • 47
18
votes
1 answer

How to push to repo after doing 'git commit --amend'

I made a commit & pushed to repo. Later I modified the commit message by using git commit --amend, In the pop-up window I entered the new message. I could see the new message via git log. After all this process, my git status shows like this. I…
user1479142
  • 181
  • 1
  • 1
  • 3
1
2 3
8 9