Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
  git commit --amend --allow-empty

then

  git push origin master

the git said that

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'remoteurl'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

Why? How to fix this?

share|improve this question
add comment

1 Answer

up vote 19 down vote accepted

The issue is not that you are pushing an empty commit.
It is about pushing a different commit (one with a different SHA1) than the one commit already pushed.
That is whar git commit --amend does: it modified the last commit, it doesn't create a new one.

That means you are pushing a different history than the one others might have already cloned.
If you are sure that won't be a problem, you need to force the push:

git push -f origin master

Should you have done:

git commit --allow-empty

you would have created a new (empty) commit, which you could have pushed without any issue.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.