git remote -v show
什麼是原產地?
如果origin指向github,狀態應該是最新的,而不是任何遠程repo。至少,使用Git1.6.5進行快速測試。
總之,要避免這種情況,定義明確主分支的遠程回購:
$ git config branch.master.remote yourGitHubRepo.git
然後git pull origin master
,隨後git status
應該返回一個乾淨的狀態(無提示)。
爲什麼?因爲獲取獲取原點主(包括在git pull原點主)不會更新FETCH_HEAD
(因爲Charles Bailey在his answer中解釋),但它會也更新本地Git存儲庫中的「遠程主分支」。
在這種情況下,您的本地主人似乎不再是遠程主人的「前面」。
我可以測試這個,用git1.6。5:
首先創建一個workrepo:
PS D:\git\tests> cd pullahead
PS D:\git\tests\pullahead> git init workrepo
Initialized empty Git repository in D:/git/tests/pullahead/workrepo/.git/
PS D:\git\tests\pullahead> cd workrepo
PS D:\git\tests\pullahead\workrepo> echo firstContent > afile.txt
PS D:\git\tests\pullahead\workrepo> git add -A
PS D:\git\tests\pullahead\workrepo> git commit -m "first commit"
我通過創建一個裸回購(其中之一可以從任何地方接收推送)
PS D:\git\tests\pullahead\workrepo> cd ..
PS D:\git\tests\pullahead> git clone --bare workrepo github
模擬GitHub庫我一個修飾的添加我的工作回購,我推github回購(作爲遠程添加)
PS D:\git\tests\pullahead> cd workrepo
PS D:\git\tests\pullahead\workrepo> echo aModif >> afile.txt
PS D:\git\tests\pullahead\workrepo> git ci -a -m "a modif to send to github"
PS D:\git\tests\pullahead\workrepo> git remote add github d:/git/tests/pullahead/github
PS D:\git\tests\pullahead\workrepo> git push github
我創建了一個家庭回購,克隆o ˚FGitHub上,我在其中做一些修改,推到GitHub上:
PS D:\git\tests\pullahead\workrepo> cd ..
PS D:\git\tests\pullahead> git clone github homerepo
PS D:\git\tests\pullahead> cd homerepo
PS D:\git\tests\pullahead\homerepo> type afile.txt
firstContent
aModif
PS D:\git\tests\pullahead\homerepo> echo aHomeModif1 >> afile.txt
PS D:\git\tests\pullahead\homerepo> git ci -a -m "a first home modif"
PS D:\git\tests\pullahead\homerepo> echo aHomeModif2 >> afile.txt
PS D:\git\tests\pullahead\homerepo> git ci -a -m "a second home modif"
PS D:\git\tests\pullahead\homerepo> git push github
我再克隆workrepo的第一個實驗
PS D:\git\tests\pullahead\workrepo4> cd ..
PS D:\git\tests\pullahead> git clone workrepo workrepo2
Initialized empty Git repository in D:/git/tests/pullahead/workrepo2/.git/
PS D:\git\tests\pullahead> cd workrepo2
PS D:\git\tests\pullahead\workrepo2> git remote add github d:/git/tests/pullahead/github
PS D:\git\tests\pullahead\workrepo2> git pull github master
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
From d:/git/tests/pullahead/github
* branch master -> FETCH_HEAD
Updating c2763f2..75ad279
Fast forward
afile.txt | Bin 46 -> 98 bytes
1 files changed, 0 insertions(+), 0 deletions(-)
在這種回購,git的狀態確實提到主geing提前'origin
':
PS D:\git\tests\pullahead\workrepo5> git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
nothing to commit (working directory clean)
不過,這只是origin
不Github上:
PS D:\git\tests\pullahead\workrepo2> git remote -v show
github d:/git/tests/pullahead/github (fetch)
github d:/git/tests/pullahead/github (push)
origin D:/git/tests/pullahead/workrepo (fetch)
origin D:/git/tests/pullahead/workrepo (push)
但是,如果我重複序列,其中有一個原點github上(或無產地可言,只需要一個遙控「GitHub的」定義),狀態是乾淨的回購:
PS D:\git\tests\pullahead\workrepo2> cd ..
PS D:\git\tests\pullahead> git clone workrepo workrepo4
PS D:\git\tests\pullahead> cd workrepo4
PS D:\git\tests\pullahead\workrepo4> git remote rm origin
PS D:\git\tests\pullahead\workrepo4> git remote add github d:/git/tests/pullahead/github
PS D:\git\tests\pullahead\workrepo4> git pull github master
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
From d:/git/tests/pullahead/github
* branch master -> FETCH_HEAD
Updating c2763f2..75ad279
Fast forward
afile.txt | Bin 46 -> 98 bytes
1 files changed, 0 insertions(+), 0 deletions(-)
PS D:\git\tests\pullahead\workrepo4> git status
# On branch master
nothing to commit (working directory clean)
如果我有隻有origin
指向github
,status
對git1.6.5來說是乾淨的。
對於早期的git,可能會提前發出警告,但無論如何,明確定義的git config branch.master.remote yourGitHubRepo.git
應該能夠處理該問題,即使是早期版本的Git也是如此。
我也注意到了這一點;一個'git push'似乎也能解決它(報告「全部是最新的」)。 – 2009-11-16 09:54:49
'git config --get-regexp br。*'可以告訴你你的配置是否有本地分支正在跟蹤另一個分支 – VonC 2009-11-16 15:08:02
你可以在你的workRepo中輸入'git config branch.master.remote yourGitHubRepo.git'並檢查如果狀態保持「提前」警告,下一個'git pull origin')? – VonC 2009-11-16 15:09:16