But I get an error "! [rejected]" and something about "non fast forward" (但我得到一个错误“![拒绝]”和“非快进”的事情)
That's because Git can't merge the changes from the branches into your current master. (那是因为Git无法将分支的更改合并到当前的主服务器中。) Let's say you've checked out branch master
, and you want to merge in the remote branch other-branch
. (假设您已经检出了分支master
,并且想要在远程分支other-branch
合并。) When you do this: (当你这样做:)
$ git pull origin other-branch
Git is basically doing this: (Git基本上是这样做的:)
$ git fetch origin other-branch && git merge other-branch
That is, a pull
is just a fetch
followed by a merge
. (也就是说, pull
只是一个fetch
然后是一个merge
。) However, when pull
-ing, Git will only merge other-branch
if it can perform a fast-forward merge. (但是,当pull
,Git 只会合并other-branch
如果它可以执行快进合并。) A fast-forward merge is a merge in which the head of the branch you are trying to merge into is a direct descendent of the head of the branch you want to merge. (快进合并是一种合并,其中您尝试合并的分支的头部是您要合并的分支的头部的直接后代 。) For example, if you have this history tree, then merging other-branch
would result in a fast-forward merge: (例如,如果您有此历史记录树,那么合并other-branch
将导致快进合并:)
O-O-O-O-O-O
^ ^
master other-branch
However, this would not be a fast-forward merge: (但是,这不是一个快速合并:)
v master
O-O-O
-O-O-O-O
^ other-branch
To solve your problem, first fetch the remote branch: (要解决您的问题,请先获取远程分支:)
$ git fetch origin other-branch
Then merge it into your current branch (I'll assume that's master
), and fix any merge conflicts: (然后将它合并到您当前的分支(我将假设它是master
),并修复任何合并冲突:)
$ git merge origin/other-branch
# Fix merge conflicts, if they occur
# Add merge conflict fixes
$ git commit # And commit the merge!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…