Tim
Tim

Reputation: 99616

Can't push again a commit after amending its comment

$ git commit -m "original comment"    
$ git push origin B02913

Then i change the comment on the commit, but fail to push to an enterprise Gibhub site:

$ git commit --amend -m "modified comment"                                                    
$ git push origin B02913                                                                            
  To https://xxx
 ! [rejected]        B02913 -> B02913 (non-fast-forward)
error: failed to push some refs to 'https://xxx'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Why can't the second push rewrite the comment of the commit already on GitHub?

What shall I do now?

Thanks.

Upvotes: 0

Views: 41

Answers (2)

Makoto
Makoto

Reputation: 106518

You've rewritten history with your --amend; that is, you should see git status report something along the lines of "your branches have diverged".

If you're confident that the only thing you've done is change just the files you care about, you'll have to force-push it onto your branch (via git push --force). This tells Git to allow you to rewrite history, but is a potentially dangerous operation as you've overwritten history.

Upvotes: 3

eftshift0
eftshift0

Reputation: 30327

You need to push with --force. That is because you amended a revision which is like forking, so when you push git is saying "well... the revision that is on the remote is not merged into the local revision I'm trying to push... so won't do it".

Upvotes: 1

Related Questions