'git pull 원산지 mybranch'잎 지역 mybranch N 앞서 커밋의 기원합니다.왜?
-
20-09-2019 - |
문제
나는 단지에 대한 이상한 관찰 git pull
, 는 내가 이해하지 못합니다.
금요일에,나는 일에 지역 지점에 있습니다.let's 화 mybranch
.사무실을 떠나기 전에 내가 밀려 그것을 기원(는 내 github repo): git push origin mybranch
.
어제,집에서 나가 pull
ed mybranch 내 노트북,았다 좀 더 코딩,그리고 그런 다음 밀어 내는 변경 다시 github(origin).
에서 지금은 다시 작업,그리고 끌어내려고 시도하에서 변경 사항을 어제 내업기(지 않았다 아무것도 변경 내에서 작동하는 장소의 현지 repo 주말):
git pull origin mybranch
이 발생하는 빠르고 앞으로 병합하는 괜찮습니다.나는 그때 git status
, 고 그는 말했다:
# On branch mybranch
# Your branch is ahead of 'origin/mybranch' by 6 commits.
#
nothing to commit (working directory clean)
Huh?할 수 있는 방법 6 커밋에서 최고지도 않았어요 그것을 만 주말에,그냥 뽑아서 원점?그래서 나는 달 git diff origin/mybranch
와 차이점이 정확히 6 변경 나는 그냥 뽑아에서 원격입니다.
할 수 있었는"수정"이에 의해 실행 git fetch origin
:
From git@github.com:me/project
af8be00..88b0738 mybranch -> origin/mybranch
분명히,나의 현지 repo 누락되었 일부 개체를 참조하지만,어떻게 그럴 수가 있습니까?I mean,풀다가 가미하고 작동하지 않았다 아무것도를 제외하고는,그래서 git fetch origin
고 git fetch origin mybranch
가 동일한 결과는?
어야 나는 항상 사용 git pull origin
대 git pull origin branchname
?
잘 모르겠습니다.
해결책
git pull
전화 git fetch
명시 적으로 페치 된 헤드를 병합하기 전에 적절한 매개 변수를 사용하여 (또는 원격 분기가 병합을 위해 구성된 원격 분기가 현재 분기에 구성된 경우).
구문 : git fetch <repository> <ref>
어디 <ref>
콜론이없는 지점 이름은 지정된 리모컨의 모든 추적 지점에 대한 표준 페치를 수행하지 않고 대신 지명 된 분기 만 가져 오는 '원사'페치입니다. FETCH_HEAD
.
업데이트: 1.8.4 이후 git 버전의 경우, 가져 오라고 요청한 Ref를 추적하는 원격 추적 브랜치가 있으면 추적 브랜치가 다음과 같이 업데이트됩니다. fetch
. 이 변화는 이전의 행동으로 인해 발생한 혼란을 피하기 위해 구체적으로 이루어졌습니다.
당신이 수행 할 때 git pull <repository> <ref>
, FETCH_HEAD
위와 같이 업데이트 된 다음 체크 아웃으로 병합 HEAD
그러나 원격 저장소의 표준 추적 분기는 업데이트되지 않습니다 (Git <1.8.4). 이것은 로컬로 그것을 의미합니다 외모 당신은 원격 지점을 앞두고있는 것처럼, 실제로 당신은 그것에 대해 최신 정보를 얻었습니다.
개인적으로 나는 항상합니다 git fetch
그 뒤에 git merge <remote>/<branch>
병합하기 전에 강제 업데이트에 대한 경고를 볼 수 있기 때문에 병합하는 것을 미리 볼 수 있습니다. git pull
나보다 조금 더, 나는 평원을 할 것이다 git pull
대부분의 시간에 매개 변수가없는 branch.<branch>.remote
그리고 branch.<branch>.merge
'올바른 일을하는 것'.
다른 팁
무엇 git remote -v show
반환에 올 때 원산지?
는 경우 원산지 포인트를 github 상태에 있어야하는 날짜,그리고지 않은 앞으로 어떤 원격 repo.에서 이상으로,Git1.6.5 내가 사용하여 빠른 시험입니다.
어쨌든,이 문제를 방지하기 위해서는,정의를 명시적으로 원격 저장소의 마지점:
$ git config branch.master.remote yourGitHubRepo.git
다음 git pull origin master
, 다음에 git status
반환해야 합니다 깨끗한 상태를(아 앞서).
왜?기 때문에 얻는 가 원산지스터(에 포함되어 있 git pull 원산지 마스터)지 않을 것입 업데이트 FETCH_HEAD
(로 샤 베일리 설명 그의 대답이어),하지만 그 도 업데이트"원격 마스터는 지점"이내에 귀하의 지역 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"
나는 시뮬레이션 GitHub repo 을 만들어 벌거벗은 repo(한을 받을 수 있는 푸시에서 어디서나)
PS D:\git\tests\pullahead\workrepo> cd ..
PS D:\git\tests\pullahead> git clone --bare workrepo github
추가 modif 내 일 repo,나는 밀 github repo(추가로 원격)
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
내가 만드는 가정 repo,복제 GitHub,에서 내가 만들 부부의 수정,밀려 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
명시적으로 정의되어야 할 수 있을 돌보는 것도의 초기 버전은 사용할 수 있습니다..
모든 리모컨을 추가해야합니까 (제외 origin
원래 클론과 함께 제공) 사용 git remote add NAME URL
? 이 버그가 GIT 구성에 방금 추가되었을 때이 버그를 보았습니다.