3
make changes
git commit 'made changes' -a
git push origin
make more changes
git ammend -a
git push origin

I've noticed that when I do a git commit --ammend -a and then try to push to a remote repo, it requires that I force the push (git push -f).

My guess is because it's trying to push the same (?whats the word?) commit code but notices differences in files.

Is this correct / normal?

d-_-b
  • 21,536
  • 40
  • 150
  • 256
  • 1
    There is no `git amend` command; are you referring to `git commit --amend`? – Marco Leogrande Sep 30 '12 at 19:43
  • @MarcoLeogrande thanks made the change i'm too used to my aliases `>_<` – d-_-b Sep 30 '12 at 19:47
  • 1
    A little off topic, but I think that after you have pushed a commit, doing an amend on that commit is a bad idea. Your commit is out there. Accept it. Create a new commit that includes the changes that you forgot to put in the original. Then push that. – Guido Simone Sep 30 '12 at 19:57

1 Answers1

7

A git commit --amend or a git commit --author=<author>, if anything is modified, will generate a different SHA1.
Then, yes, a git push -f will be needed.

git amend can be defined as an alias like in this blog post:

git config --global alias.amend 'commit --amend -C HEAD'

This alias adds a git amend command that will reuse the current commit message when it amend it.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    See also, for additional information: http://stackoverflow.com/a/10728453/6309. Beware of the danger of a `git push -f` though ;) http://stackoverflow.com/questions/253055/how-do-i-push-amended-commit-to-the-remote-git-repo – VonC Sep 30 '12 at 19:47
  • THanks @VonC just as I suspected. So is there any way to circumvent this or to know if it is safe to ignore it? (I can think to pull the remote locally and `git diff` ?) – d-_-b Sep 30 '12 at 19:49
  • @iight ignore the `push -f`? You won't be able, if you want to push back an *amended* commit (ie, the same content, with a different SHA1 because of an amended metadata information). – VonC Sep 30 '12 at 19:51