2011-11-18 71 views
3

有時候我通過#提交得到一些分支在原點前面的消息。實際上,我沒有創建這些提交,並且它們是從原來的。分支遠程HEAD的奇怪行爲

$> git pull origin develop 
Enter passphrase for key '###': 
remote: Counting objects: 7, done. 
remote: Compressing objects: 100% (4/4), done. 
remote: Total 4 (delta 2), reused 0 (delta 0) 
Unpacking objects: 100% (4/4), done. 
From ssh://git.############# 
* branch   develop -> FETCH_HEAD 
Updating bbe5577..71907bc 
Fast-forward 
############### | 1 - 
1 files changed, 0 insertions(+), 1 deletions(-) 

而且

$> git st 
# On branch develop 
# Your branch is ahead of 'origin/develop' by 1 commit. 

tig的輸出:

{date} {author} [develop] {message1} 
{date} {author} [origin/develop] {message2} 

所以,如果我理解沒事,產地的頭我的地方HEAD(或類似的東西)的支持通過1.但沒有人修復該起源的頭到-1狀態。

爲什麼會發生?

然後我推到一個分支,並獲得「一切先進的日期」

$> git push origin develop 
Enter passphrase for key '###': 
Everything up-to-date 

有人能解釋這是怎麼回事與該分支?

回答

2

簡短的回答是使用git fetch origin隨後git merge origin/develop從當地的開發分支

git pull就像是一個git fetch接着是git merge在當地分行的發展。雖然您的本地副本是來自您的起源/開發HEAD的前一個提交,但您當前存儲庫中的起源/開發將與您當地的開發分支不匹配。撥打git push origin develop更新您當地的起源/發展,當git意識到變化已經在遠程git回購。

這裏就是你在本地看到你的機器上沒有變化:

macbook:test joel$ git push origin master 
Everything up-to-date 
macbook:test joel$ git status 
# On branch master 
nothing to commit (working directory clean) 
macbook:test joel$ 

在另一臺計算機的其他用戶進行了更改,提交它,並將其推到原點/主:

otherPerson-pc:test bob$ git status 
# On branch master 
nothing to commit (working directory clean) 
otherPerson-pc:test bob$ echo "ddd" >> newfile.txt 
otherPerson-pc:test bob$ git add newfile.txt 
otherPerson-pc:test bob$ git commit --message "added to newfile in master remotely" 
[master d14b77e] added to newfile in master remotely 
1 files changed, 1 insertions(+), 0 deletions(-) 
otherPerson-pc:test bob$ git push origin master 
Counting objects: 5, done. 
Delta compression using up to 8 threads. 
Compressing objects: 100% (2/2), done. 
Writing objects: 100% (3/3), 314 bytes, done. 
Total 3 (delta 0), reused 0 (delta 0) 
Unpacking objects: 100% (3/3), done. 
To /Users/joel/Desktop/test/test.git 
    2cfa7d4..d14b77e master -> master 
otherPerson-pc:test bob$ 

回到我的本地副本,我沒有做出任何改變。我從產地主拉從別人那裏得到改變,並出現一個承諾未來!:

macbook:test joel$ git status 
# On branch master 
nothing to commit (working directory clean) 
macbook:test joel$ git pull origin master 
remote: Counting objects: 5, done. 
remote: Compressing objects: 100% (2/2), done. 
remote: Total 3 (delta 0), reused 0 (delta 0) 
Unpacking objects: 100% (3/3), done. 
From /Users/joel/Desktop/test/test 
* branch   master  -> FETCH_HEAD 
Updating 2cfa7d4..d14b77e 
Fast-forward 
newfile.txt | 1 + 
1 files changed, 1 insertions(+), 0 deletions(-) 

macbook:test joel$ git status 
# On branch master 
# Your branch is ahead of 'origin/master' by 1 commit. 
# 
nothing to commit (working directory clean) 
macbook:test joel$ 

我的本地主有從遙控器上的主應用的變化,但我出身/主副本爲1提交之後,以便混帳說我」即使我是最新的,我也可以在本地提前完成。 git push origin master本地更新origin/master,消息消失。

您可以通過使用git fetchgit merge,而不是git pull

的其他開發人員避免這種情況可能會再次做到這一點:

otherPerson-pc:test bob$ git status 
# On branch master 
nothing to commit (working directory clean) 
otherPerson-pc:test bob$ echo "gggg" >> newfile.txt 
otherPerson-pc:test bob$ git add newfile.txt 
otherPerson-pc:test bob$ git commit --message "added gggg newfile in master remotely" 
[master 677d031] added eeee newfile in master remotely 
1 files changed, 1 insertions(+), 0 deletions(-) 
otherPerson-pc:test bob$ git push origin master 
Counting objects: 5, done. 
Delta compression using up to 8 threads. 
Compressing objects: 100% (2/2), done. 
Writing objects: 100% (3/3), 321 bytes, done. 
Total 3 (delta 0), reused 0 (delta 0) 
Unpacking objects: 100% (3/3), done. 
To /Users/joel/Desktop/test/test.git 
    d14b77e..677d031 master -> master 
otherPerson-pc:test bob$ 

本地我的git獲取所有來源,然後手動合併產地/掌握到我的合併副本。

macbook:test joel$ git status 
# On branch master 
nothing to commit (working directory clean) 


macbook:test joel$ git fetch origin 
remote: Counting objects: 5, done. 
remote: Compressing objects: 100% (2/2), done. 
remote: Total 3 (delta 0), reused 0 (delta 0) 
Unpacking objects: 100% (3/3), done. 
From /Users/joel/Desktop/test/test 
    5e335fa..2dae61c master  -> origin/master 

macbook:test joel$ git status 
# On branch master 
# Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded. 
# 
nothing to commit (working directory clean) 

macbook:test joel$ git merge origin/master 
Updating 5e335fa..2dae61c 
Fast-forward 
newfile.txt | 1 + 
1 files changed, 1 insertions(+), 0 deletions(-) 

macbook:test joel$ git status 
# On branch master 
nothing to commit (working directory clean) 
macbook:test joel$ 

我通常做一個提取然後合併,因爲你可以在你使用git diff合併之前檢查衝突。