Co git remote -v showzwraca, jeśli chodzi o pochodzenie?
Jeśli źródło wskazuje na github, stan powinien być aktualny i nie wyprzedzać żadnego zdalnego repozytorium. Przynajmniej z Git1.6.5 używam do szybkiego testu.
W każdym razie, aby tego uniknąć, zdefiniuj jawnie zdalne repozytorium gałęzi głównej:
$ git config branch.master.remote yourGitHubRepo.git
następnie a git pull origin master, po którym następuje a, git statuspowinny zwrócić stan czysty (nie z wyprzedzeniem).
Czemu? ponieważ wzorzec pochodzenia pobierania pobierania (zawarty w wzorcu pochodzenia git pull) nie tylko aktualizowałby FETCH_HEAD(jak wyjaśnia w swojej odpowiedzi Charles Bailey ), ale także aktualizowałby „zdalną gałąź główną” w lokalnym repozytorium Git.
W takim przypadku twój lokalny master nie wydaje się już być „przed” zdalnym masterem.
Mogę to przetestować za pomocą git1.6.5:
Najpierw tworzę 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"
Symuluję repozytorium GitHub, tworząc gołe repozytorium (takie, które może otrzymywać push z dowolnego miejsca)
PS D:\git\tests\pullahead\workrepo> cd ..
PS D:\git\tests\pullahead> git clone --bare workrepo github
Dodaję modyfikację do mojego działającego repozytorium, którą wciskam do repozytorium github (dodanego jako zdalne)
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
Tworzę repozytorium domowe, sklonowane z GitHuba, w którym dokonuję kilku modyfikacji, wypychanych do GitHuba:
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
Następnie klonuję workrepo do pierwszego eksperymentu
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(-)
W tym repozytorium status git wspomina o masteringu przed „ 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)
Ale to tylko originnie jest 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)
Ale jeśli powtórzę sekwencję w repozytorium, które ma początek w githubie (lub w ogóle nie ma źródła, zdefiniowano tylko zdalny „github”), status jest czysty:
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)
Gdybym tylko originwskazywał na github, statusbyłby czysty dla git1.6.5.
Może to być ostrzeżenie „z wyprzedzeniem” dla wcześniejszego gita, ale tak czy inaczej, git config branch.master.remote yourGitHubRepo.gitzdefiniowany wyraźnie powinien być w stanie się tym zająć, nawet we wczesnych wersjach Gita.
git pushtakże wydaje się, że rozwiązuje ten problem (raportowanie „wszystkie aktualne”).