简体   繁体   中英

How to push a branch to github after amending a commit?

I have amended a commit in a branch(not the master branch) in my local repo using this code git commit --amend --no-edit but how to push this to github? I had already pushed the branch before amending the commit. Now i just want the change to commit in my local repo(done using git commit --amend --no-edit ) to be reflected in github also. How can i achieve this?

You need to force push the branch:

git push --force origin some_branch

The reason why an ordinary push will fail is that in the process of amending the top most commit, you actually have rewritten that commit entirely.

Here is a diagram showing what some_branch would look like after amending the head commit:

remote: ... A -- B
              \
local:          B'     (the prime indicates a new commit)

In other words, from Git's point of view it is as if your local and remote branches have actually diverged from each other. Now, the A commit is the most recent ancestor. You probably want to keep your local version, and if so then you need to force push.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM