Issue
I merged a branch in a master not updated at last commit.
What I do
I merged a branch in master
git merged BRANCHNAME
Conflicts
Automatic merge failed; fix conflicts and then commit the result.
git commit -a -m "Resolved conflicts 开发者_如何学Pythonwhile merging email-fix branch"
Then I tried to push all to origin master, but it says:
! [rejected] master -> master (non-fast-forward)
How can I solve this problem?
You can do:
- a
git pull --rebase
, in order to replay your merge on top of an up-to-date master branch - then a
git push
(which should go smoothly)
The other alternative would be to force the push, which would mean loosing the recent history on the remote master: not a very good idea.
Both alternatives are presented in the Git FAQ, although only a simple git pull
is advocated.
The git push
man page mentions the git pull --rebase
:
For example, suppose you and somebody else started at the same commit
X
, and you built a history leading to commitB
while the other person built a history leading to commitA
. The history looks like this:
B
/
---X---A
Alternatively, you can rebase your change between
X
andB
on top ofA
, with "git pull --rebase
", and push the result back. The rebase will create a new commitD
that builds the change betweenX
andB
on top ofA
.
B D
/ /
---X---A
Again, updating
A
with this commit will fast-forward and your push will be accepted.
精彩评论