2012-01-23 144 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