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
8
votes
3 answers

If I push an amended commit will it create a new commit?

I have already pushed a commit on the remote branch and now I want to change its content, so I tried git amend. If do git status it says that the two branches have 1 and 1 different commits each, respectively. Now if I push the amended commit with…
lads
  • 1,125
  • 3
  • 15
  • 29
8
votes
3 answers

Git amend/reword (without adding/changing files)

Often I want to edit a commit message without having to re-select the file-set from the last commit. git commit file1.c file2.c Accidental typo in commit message. git commit file1.c file2.c --amend This works, but Id like not to have to re-select…
ideasman42
  • 42,413
  • 44
  • 197
  • 320
6
votes
1 answer

git commit --amend - commit hash is changed when no changes are made

I open for some correction of my understanding of this, but I am not sure why this happens. When using git, I understand that if I make a change to a file and then commit it I get a new hash because the file has changed. My understanding of git…
jwknz
  • 6,598
  • 16
  • 72
  • 115
6
votes
3 answers

Git commit --amend merged two commits

I have a remote 'dev' branch and was working on it locally. I made a first commit on 'dev' with a commit message "my_feature", putting my local branch ahead of the remote by 1 commit. I then developed some new stuff and made a git add -u, getting…
shkschneider
  • 17,833
  • 13
  • 59
  • 112
6
votes
3 answers

How to change author name on git branch

I branched my github project to create the static page the other day but messed up with my author name https://github.com/ronaldsuwandi/le-simplepage/commits/gh-pages How do I rename the author for the first commit for the branch? I've tried…
GantengX
  • 1,471
  • 2
  • 16
  • 28
4
votes
3 answers

Amend a Mercurial commit without an editor window opening?

When I use mercurial command (hg commit --amend) it always opens up the editor window. In git I can avoid this by git commit -a --amend -CHEAD, is there something equivalent for mercurial?
A. K.
  • 34,395
  • 15
  • 52
  • 89
4
votes
1 answer

git --amend --no-edit rejected push

Today I discovered the --no-edit for the --amend. However, it leads me to the following problem. Here the steps: git clone did some changes to the code git add . git commit --amend --no-edit git push origin master ! [rejected] master ->…
Emaborsa
  • 2,360
  • 4
  • 28
  • 50
4
votes
2 answers

Edit incorrect commit message in GitHub for Windows

I've managed to muck up a commit message bad enough, that when I read it back, even I can't work out what is says! This commit hasn't been pushed and I know that the message can be changed with: git commit --amend -m "New commit message" (thanks to…
james12802
  • 335
  • 1
  • 4
  • 11
4
votes
2 answers

Why doesn't git amend warn you when there's nothing to amend?

I oftentimes make the mistake of making a change to a file right after a commit, then running git commit --amend followed by a quick git push -f origin master The issue, obviously, is that I never ran git add foo.md. So my amend didn't actually…
acco
  • 550
  • 6
  • 13
4
votes
2 answers

Changing the code of previous commits with git rebase -i

I have a repository with various commits which I want merged in two patches. One patch introducing the feature and another changing the existing code to use it. Problem is, when I was coding and committing I didn't have that in mind, so there are…
ndp
  • 873
  • 1
  • 11
  • 24
3
votes
3 answers

git - fatal: your current branch appears to be broken (possibly from interrupted pull)

Problem: accidentally did a git --amend and pushed it to a usb key from first computer pulled from the usb key to a second computer second computer repository is now corrupted git pull to first computer results in a merge conflict; confused about…
ninjagecko
  • 88,546
  • 24
  • 137
  • 145
3
votes
1 answer

git commit amendment without losing the tags

I have the following script that runs on post-commit hook of Git: #!/bin/sh # by Martin Seeler, and # by Jorge Javier Araya Navarro # destination of the final changelog file OUTPUT_FILE=CHANGELOG.md # generate the changelog if ! type gitchangelog…
shackra
  • 277
  • 3
  • 16
  • 56
3
votes
3 answers

I amended instead of resolving conflict in interactive rebase. Can I undo?

I was doing a big interactive rebase where I was editing something like 8 commits. This is done with git commit --amend. My issue is that at one point I got a merge conflict which I did not notice, so I kept on naively amending and git rebase…
Automatico
  • 12,420
  • 9
  • 82
  • 110
3
votes
2 answers

How do I push amended commit to the remote git repo on a specific commit

I already edit some files in my repo and push them. After some other work, I noticed that i keep a line commented. So, i don't want to create a new commit for it and I want to change it in the previous commit (Not the last one commit). I think that…
craken
  • 1,411
  • 11
  • 16
3
votes
1 answer

Git commit message with letter #

I have a little problem. In our company we have an agreement that all commits that related to some issue in bug tracker should start with # (for example, #8956). But git ignores all of the lines that starts with letter '#' when writing…
DeGriz
  • 318
  • 3
  • 15
1 2
3
9 10