23

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 don't know how to push this change to repo.

On branch master
Your branch and `origin/master` have diverged,
and have 1 and 1 different commit(s) each, respectively.

Expecting a feasible solution for this.

Martin G
  • 17,357
  • 9
  • 82
  • 98
user1479142
  • 231
  • 1
  • 2
  • 3
  • Are you okay with splitting the commit again and building on the already published (leaked?) head? – Thilo Jun 25 '12 at 06:22
  • See [master branch and 'origin/master' have diverged, how to 'undiverge' branches'?](http://stackoverflow.com/questions/2452226/master-branch-and-origin-master-have-diverged-how-to-undiverge-branches) – Christopher Peisert Jun 25 '12 at 06:40
  • If you can avoid amending commits once they've been pushed to a public place where other people can see them, you absolutely should. This goes for rebasing too. – Matthew G Aug 23 '13 at 06:15

1 Answers1

28

2012: If you are ok with modifying the history on the remote repo (as in, you just pushed that commit, and no new commits were made), you can try a

git push --force 

However, do read first "How do I push amended commit to the remote git repo?": if anyone already pulled from that repo, he/she won't be happy.

An alternative is described in "Git: pushing amended commits".
As mentioned by cpeisert in the comment "master branch and 'origin/master' have diverged, how to 'undiverge' branches'?" described your warning message.


2022: note that git push --force-with-lease is safer than git push --force.

And you also have git push --force-if-includes (Git 2.30+), which attempts to ensure that what is being force-pushed was created after examining the commit at the tip of the remote ref that is about to be force-replaced.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250