Git - Your branch and 'origin/xxx' have diverged
2017-09-01 00:00
766 查看
当前工作的Git仓库模型为:
1
2
3
4
5
1
2
3
4
5
提示类似下面的错误:
1
2
1
2
出现分叉的原因是存在两种独立的提交(每种可能有多个提交): 一种是来自你本地分支副本的提交,另外的提交来自远程分支副本。(通常是由于另外一个人在上游相同的分支做了提交)
一个示例的git提交历史树:
1
2
3
4
5
1
2
3
4
5
这个时候解决分叉的办法就是:
在本地分支上,执行:
1
1
rebase以后的git提交历史树为:
1
2
3
1
2
3
rebase之前的git提交历史树:
1
2
3
4
1
2
3
4
执行rebase之后的git提交历史树:
1
2
3
1
2
3
这时候,你必须确定你是处于上面描述的情况,解决方案就是强制push到你的origin上游,执行下面命令可以解决:
upstream | origin | local copy
1
2
3
4
5
1
2
3
4
5
Git fetch 、merge以后出现分叉
git fetchupstream上游代码后执行
git merge,然后
git status发现Git分支出现分叉 (不是在
rebase之后出现的情况下)。
提示类似下面的错误:
Your branch and 'origin/xxx' have diverged, and have 1 and 1 different commit(s) each, respectively.
1
2
1
2
出现分叉的原因是存在两种独立的提交(每种可能有多个提交): 一种是来自你本地分支副本的提交,另外的提交来自远程分支副本。(通常是由于另外一个人在上游相同的分支做了提交)
一个示例的git提交历史树:
... o ---- o ---- A ---- B origin/branch_xxx (upstream work) \ C branch_xxx (your work)
1
2
3
4
5
1
2
3
4
5
这个时候解决分叉的办法就是:
在本地分支上,执行:
git rebase
1
1
rebase以后的git提交历史树为:
... o ---- o ---- A ---- B origin/branch_xxx (upstream work) \ C` branch_xxx (your work)
1
2
3
1
2
3
rebase以后提示同样的错误
rebase以后可能出现相同的错误,这是因为你在执行rebase之前,已经往你的origin上面push了提交。由于rebase会重写历史提交记录,因此你的本地和你的origin的历史提交状态是不同的,同样产生了分叉:rebase之前的git提交历史树:
... o ---- o ---- A ---- B master, origin/master \ C branch_xxx, origin/branch_xxx
1
2
3
4
1
2
3
4
执行rebase之后的git提交历史树:
... o ---- o ---- A ---------------------- B master, origin/master \ \ C origin/branch_xxx C` branch_xxx
1
2
3
1
2
3
这时候,你必须确定你是处于上面描述的情况,解决方案就是强制push到你的origin上游,执行下面命令可以解决:
git push origin branch_xxx -f
相关文章推荐
- Git - Your branch and 'origin/xxx' have diverged
- git: Your branch and 'origin/master' have diverged
- git: Your branch and 'origin/master' have diverged
- Your branch and 'XXX' have diverged
- Your branch and 'origin/master' have diverged,
- git: Your branch and 'origin/master' have diverged
- [小技巧] git: Your branch and 'origin/master' have diverged
- Show current Git branch and status in your prompt
- git status message - Your branch is ahead of origin/master by X commits
- npm ERR! Please check if you have git installed and in your PATH.
- [置顶] "On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to ..."解决
- git Your branch is ahead of 'origin/master'
- 解决git中upstream丢失问题Your branch is based on 'origin/xxxx', but the upstream is gone.
- Git Your branch is ahead of 'origin/master' by X commits解决方法
- Git branch has diverged after rebase
- Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME
- Table 'xxx' is marked as crashed and should be repaired解决方案
- git出错"Your branch is ahead of 'origin/LS3A_2H' by 4 commits"解决
- eclipse git 报错:the current branch is not configured for pull No value for key branch.xxx.merge found
- git checkout -b时fatal: Cannot update paths and switch to branch '' at the same time.解决方案