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

146 questions
23
votes
3 answers

Git - Difference between amend and squash commands

What is the difference between amend and squash commands? I tried both and found that both are doing the same for proper management.
Raju Guduri
  • 1,237
  • 1
  • 13
  • 25
23
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
  • 231
  • 1
  • 2
  • 3
20
votes
2 answers

git merge conflict after git amend - "Your branch and 'origin/master' have diverged"

This is what happens: After a recent commit to remote master, I make a small trivial change to my local repo I add git commit --amend and leave the same commit message as HEAD I try to push the repo to master with git push And now I get On branch…
Amit Erandole
  • 11,995
  • 23
  • 65
  • 103
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
  • 5,070
  • 2
  • 30
  • 49
18
votes
1 answer

How to git commit --amend a commit that's the base of a branch

I have branch foo off of master/head. I wanted to ammend the master/head and have these changes picked up on branch foo. I did the following: git checkout master git add ... git commit --amend git checkout foo git rebase master The problem was…
Aaron
  • 1,141
  • 1
  • 11
  • 21
17
votes
1 answer

'git commit --amend' in detached HEAD state

I understand that the correct way of amending an old Git commit is to use rebase --interactive, but just to get clear on the concepts, I would like to understand what happens when I do git checkout change something in a file add the…
Chris
  • 4,212
  • 5
  • 37
  • 52
16
votes
3 answers

How can I edit an old git commit message programmatically?

You can programmatically edit only the last commit message: git commit --amend -m 'xxxxxxx' Or a random commit interactively: git rebase -i HEAD~n # Vim opens up, select the commit you want to modify, and change the word "pick" for "edit" git…
Jesus H
  • 1,180
  • 3
  • 13
  • 25
15
votes
2 answers

git fake merge (marking a commit as merged without a real merge)

Assume I have the following history in my repository: E--F / A--B--C---D And I want to modify it to be this: E--F / \ A--B--C---D I don't want to modify file content of revisions, I just want to "draw a merge arrow". How can I…
anton_rh
  • 8,226
  • 7
  • 45
  • 73
15
votes
3 answers

How to create a new Patchset in Gerrit?

I am new to Gerrit and want to create a new Patch when new changes are submitted. I setup Gerrit with this guide https://review.typo3.org/Documentation/install-quick.html Then I try to create a new patch with…
Gangaraju
  • 4,406
  • 9
  • 45
  • 77
14
votes
5 answers

How do I add a co-author to latest pushed git commit?

I need to add a co-author to my last commit and I tried using git commit --amend --author="name " but change --author to --co-authored-by. I thought this would be an easily google-able fix but everything is only for authors and not…
GabbyJ
  • 238
  • 3
  • 9
13
votes
2 answers

How to undo the initial commit on a remote repository in git?

If my very first commit is wrong, yet pushed to a (currently private) remote, how do I undo that commit on the remote? I'm guessing I can just amend and then push --force?
Dan Bolser
  • 871
  • 1
  • 9
  • 17
11
votes
1 answer

Change commit message for specific commit

Note: similar question as this one, but with some important changes. I have the following function to rewrite the date of a commit, given the commit id: rewrite-commit-date () { local commit="$1" local newdate="$2" newdate="$(date -R…
blueFast
  • 41,341
  • 63
  • 198
  • 344
11
votes
2 answers

Amending a pushed commit message

I just made pushed a commit, then realized I needed to change the commit message. So on my local repo I did: git commit --amend -m "New commit message" But when I then tried to push this, I got loads of error messages saying Updates were rejected…
Lars
  • 7,908
  • 11
  • 52
  • 70
9
votes
2 answers

Make a diff with amend commit

I wonder is that possible to show diff between two commits one of what is amend ? In other words does git save amended commits in history somewhere?
Michael Z
  • 3,883
  • 10
  • 43
  • 57
8
votes
1 answer

amending a commit after it has been pushed

In my most recent commit to my repository that has already been pushed, I noticed I misspelled a single word in a file and now would like to change it. However, I do not want to create a whole new commit. Is there a way to amend my latest commit and…
Shahin
  • 1,196
  • 1
  • 8
  • 15
1
2
3
9 10