2012-01-23 96 views
1

我对以下事件顺序有几个问题。关于分歧的GIT分支

有2位开发人员正在研究此代码。首先,是什么原因导致分支在第一个位置发生分歧?

11:05:08 ~/myApp $ git status 
# On branch Dev 
# Your branch and 'origin/Dev' have diverged, 
# and have 1 and 3 different commit(s) each, respectively. 
# 
nothing to commit (working directory clean) 
11:10:39 ~/myApp $ git push origin Dev:Dev 
To ssh://[email protected]/myApp-web.git 
! [rejected]  Dev -> Dev (non-fast-forward) 

error: failed to push some refs to 'ssh://[email protected]/myApp-web.git' 
To prevent you from losing history, non-fast-forward updates were rejected 
Merge the remote changes (e.g. 'git pull') before pushing again. See the 
'Note about fast-forwards' section of 'git push --help' for details. 

由于Git的建议,我试图从remote/Dev做拉当地Dev,只看到:但是

11:10:51 ~/myApp $ git pull origin Dev:Dev 
From ssh://mygitserver/myApp-web 
! [rejected]  Dev  -> Dev (non-fast-forward) 

的Git拉合作。 为什么git pull工作和git拉起源Dev:Dev失败?

11:13:05 ~/myApp $ git pull 
Merge made by recursive. 
WebContent/BL/a.jsp    | 14 +++++------- 
WebContent/RJ/b.jsp    | 3 +- 
.../RJ/c.jsp      | 22 ++++++++++---------- 
WebContent/RJ/d.jsp    | 14 ++++++------ 
WebContent/TM/e.jsp    | 12 ++++------ 
5 files changed, 31 insertions(+), 34 deletions(-) 

随后git statusgit push origin Dev:Dev工作没有冒险。

回答

1

分支机构发生变化时,当您的本地存储库上的远程AND发生更改时,将其视为隐式分支:两次(或多次)提交相同的父提交。有人推新提交到存储库中,当你已经不同步(合并或衍合)

至于git pull origin Dev:Dev不工作本地提交:

git pull小号manpage介绍其用法为:

git pull [options] [<repository> [<refspec>...]] 

refspec部分告诉git哪(远程)引用它应该合并到本地裁判。因此,它只允许快进更新,以防止您丢失历史记录。

你大概意思来更新您的远程跟踪分支,而不是当地的一个:

git pull origin dev:refs/remotes/origin/dev 

为您的使用情况下的快捷符号,虽然存在:

git pull origin dev: 

git pull不带参数会更新已配置远程的所有跟踪分支(通常为origin),并将第一个refspec合并到当前分支中。

+1

对于OP:远程的变化发生*和*本地资源库的真正含义,别人做了更改,并将其推到远程,所以认为它是发散的发展由你做和至少一个其他开发商。 – Cascabel

1

为了显示分歧,您只需在两台机器上比较git log Dev

+0

或更容易,因为你可以在一台机器上进行所有提交:'git fetch origin; git log --oneline --graph --decorate Dev ... origin/Dev' – knittl