开发者

Merging a branch on a not updated master

开发者 https://www.devze.com 2023-01-22 04:22 出处:网络
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

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 commit B while the other person built a history leading to commit A. The history looks like this:

      B
     /
 ---X---A

Alternatively, you can rebase your change between X and B on top of A, with "git pull --rebase", and push the result back. The rebase will create a new commit D that builds the change between X and B on top of A.

      B   D
     /   /
 ---X---A

Again, updating A with this commit will fast-forward and your push will be accepted.

0

精彩评论

暂无评论...
验证码 换一张
取 消