深入理解git分支分叉(branch diverged)的问题

翻译 2015年02月27日 17:47:14

问:

I googled and read many posts, but none could make me understand the branch divergence problem yet.

If I've remote tracking branch, I often get into the following:

$ git status
# On branch feature/worker-interface
# Your branch and 'origin/feature/worker-interface' have diverged,
# and have 1 and 4 different commit(s) each, respectively.
答:

First, you can use the cherry command to see what commits differ between branches, and in what ways. So in this case, running g cherry origin/feature/worker-interface shows us the status of commits on the current branch and how they stack up against origin/feature/worker-interface. You will find 1 repo which you forgot to commit.

首先,你可以使用git cherry命令查看提交的分支的不同,也就是说你可以git cherry origin/master 查看,显示在当前分支origin/master下提交的状态,你将发现有1个版本库你忘记了提交。

Now, lets see whats happening with the 'origin/feature/worker-interface' and its commits.For this we can run a log command with a special format gl ..origin/feature/worker-interface --oneline

现在,让我们看看origin/master到底发生了什么情况,我们用git log ..origin/master --online 查看。

Here we see 4 commits that don't exist in our current branch

我们发现有4个提交在我们的当前分支下不存在。

So now we have a good idea of what’s happened. you’ve made 1 commits on your local master branch, and it looks like there are 4 commits on origin/feature/worker-interface which you don’t have merged in yet. So, you could just blindly merge things together and go on your way (if they merge without conflict), but I’d like to show you how to deal with it in a more controlled manner.

所以我们很想知道这到底是什么原因导致了这种情况的发生。你在本地的master分支提交了一次,但是看上去应该是四次提交,这四次提交你都还没有进行合并过。那么,你可能盲目的把它们进行合并,但我将告诉你这应该怎么更好的处理这个问题:

1) First, create a branch that points to your current HEAD: gco -b local_changes 2) Now that we have that to keep track of those changes, we switch back to feature/worker-interface: gco feature/worker-interface 3) At this point, reset the feature/worker-interface branch to get rid of the 1 commit. 4) There you go! You can check your status of branch git status you will be prompted asnothing to commit


1),你应该创建一个分支指向你当前的HEAD ,如果有分支可以不用创建(git checkout -b local_changes)

2) 现在我们可以追踪到分支上的变化,我们切回到origin/master ,git checkout origin/master

3)之后git reset origin/master 删除origin/master 分支上的一次提交

4)OK,完工。git status查看下。

参考:http://stackoverflow.com/questions/9189413/good-and-clear-understanding-of-the-git-branches-diverged-issue

[小技巧] git: Your branch and 'origin/master' have diverged

本文参考:http://stackoverflow.com/questions/19864934/git-your-branch-and-origin-master-have-diverged-how...
  • robertsong2004
  • robertsong2004
  • 2016-01-06 19:27:09
  • 10371

Git - Your branch and 'origin/xxx' have diverged

Git fetch、merge上游代码后执行git status提示Your branch and 'origin/xxx' have diverged
  • d6619309
  • d6619309
  • 2016-09-30 14:20:07
  • 7384

git 问题之解决

错误
  • wwq444968579
  • wwq444968579
  • 2014-10-15 16:13:58
  • 6492

Your branch and 'origin/master' have diverged,

因为开发环境有区别,同事和我安装的包也有区别,不小心把他的apache4php这个包删除了,后面线上支付出了问题,后面就有点混乱了,然后今早拉取最新代码的时候就出现如题那个错误,说我的本地和远程分叉了...
  • zhezhebie
  • zhezhebie
  • 2018-01-22 16:25:31
  • 81

Your branch and 'origin/master' have diverged, and have 1 and 1 different commits each, respectively

当我们在本地提交到远程仓库的时候,如果遇到上述问题,我们可以首先使用如下命令: git rebase origin/master 然后使用 git pull --rebase ...
  • m0_37884977
  • m0_37884977
  • 2017-12-26 14:10:28
  • 129

Your branch and 'XXX' have diverged

目前没什么好办法,我的做法是新建一条branch,删掉这条有问题的branch。。(这份code最好保存一份)...
  • kg_second
  • kg_second
  • 2015-03-26 15:29:29
  • 1799

Your branch is ahead of 'origin/master' by 1 commit

如果只在本地修改,还没有commit,那么用git status, 打印信息为: # On branch master # Changes not staged for commit: #   ...
  • leeagle
  • leeagle
  • 2012-08-01 16:01:00
  • 39421

Git branch has diverged after rebase

最近在使用git的过程中遇到了以下问题:Your branch and 'origin/xxx' have diverged
  • d6619309
  • d6619309
  • 2017-05-20 19:22:06
  • 544

git分支branch详解

上一篇git的基本原理http://blog.csdn.net/xiaoputao0903/article/details/23912561,介绍了git最基本的原理和相关操作,这篇就来讲讲git的分...
  • xiaoputao0903
  • xiaoputao0903
  • 2014-04-17 18:44:15
  • 5042

Git 命令 创建与合并分支

创建与合并分支 1.  创建分支      git  branch name 2.  切换分支      git checkout name 3. 1+2       git checkout -b ...
  • tina_tian1
  • tina_tian1
  • 2015-08-25 14:42:41
  • 328
收藏助手
不良信息举报
您举报文章:深入理解git分支分叉(branch diverged)的问题
举报原因:
原因补充:

(最多只允许输入30个字)