Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 778
user1479142 Avatar asked Jun 25 '12 06:06

user1479142


People also ask

How do I push a commit after amending?

Changing the latest Git commit message If the message to be changed is for the latest commit to the repository, then the following commands are to be executed: git commit --amend -m "New message" git push --force repository-name branch-name.

What happens when you amend a commit?

Amended commits are actually entirely new commits and the previous commit will no longer be on your current branch. This has the same consequences as resetting a public snapshot. Avoid amending a commit that other developers have based their work on.


1 Answers

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.

like image 176
VonC Avatar answered Oct 17 '22 07:10

VonC