Alex Rivera | Logout

How to push to repo after doing 'git commit --amend'

Asked 2012-06-25T06:18:20.783
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.

Edit
Report

1 Answer

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.

answered 2012-06-25T06:52:41.430

Your Answer