program story

원격 추적 분기에서 'git fetch'및 'git merge'를 어떻게 수행합니까 (예 : 'git pull')

inputbox 2020. 7. 28. 08:31
반응형

원격 추적 분기에서 'git fetch'및 'git merge'를 어떻게 수행합니까 (예 : 'git pull')


git에서 원격 추적 분기를 설정했지만 'git fetch'로 업데이트 한 후에는 로컬 분기로 병합 할 수없는 것 같습니다.

예를 들어 'an-other-branch'라는 원격 지점이 있다고 가정합니다. 나는 그것을 사용하여 추적 지점으로 로컬로 설정했습니다.

git branch --track an-other-branch origin/an-other-branch

여태까지는 그런대로 잘됐다. 그러나 해당 분기가 업데이트되면 (일반적으로 컴퓨터를 이동하고 해당 컴퓨터에서 커밋하여) 원래 컴퓨터에서 업데이트하려고하면 가져 오기 / 병합에 문제가 있습니다.

git fetch origin an-other-branch
git merge origin/an-other-branch

이 작업을 수행 할 때마다 '이미 최신'메시지가 표시되고 병합되지 않습니다.

그러나

git pull origin an-other-branch

항상 예상대로 업데이트합니다.

또한 git diff 실행

git diff origin/an-other-branch

차이점이 있음을 보여 주므로 구문이 잘못되었다고 생각합니다.

내가 뭘 잘못하고 있죠?

편집 [2010-04-09] : 몇 번 확인했는데 다른 지점에 있지 않습니다. 내 'git fetch'다음에 'git merge'(위 그림 참조)가 git pull과 정확히 동일한 작업을 수행해야합니까? 자식 상태 등의 결과를 보여주는 워크 플로우를 얻습니다.


지점을 가져 오지 않고 전체 리모콘을 가져옵니다.

git fetch origin
git merge origin/an-other-branch

하나의 지점 만 선택 : fetch/ merge vs. pull

사람들은 종종 "가져 오기"와 "병합"을 분리하라고 조언합니다. 그들은 이것 대신에 말합니다 :

    git pull remoteR branchB

이 작업을 수행:

    git fetch remoteR
    git merge remoteR branchB

그들이 언급하지 않은 것은 그러한 페치 명령이 실제로 원격 저장소에서 모든 분기를 페치 한다는 것입니다.이 명령은 풀 명령이 하는 것이 아닙니다 . 원격 저장소에 수천 개의 지점이 있지만 모든 지점을보고 싶지 않은 경우이 모호한 명령을 실행할 수 있습니다.

    git fetch remoteR refs/heads/branchB:refs/remotes/remoteR/branchB
    git branch -a  # to verify
    git branch -t branchB remoteR/branchB

물론, 그것은 엄청나게 기억하기 어렵 기 때문에 모든 브랜치를 가져 오는 것을 피하고 싶다면 .git/configProGit에 설명 된대로 변경하는 것이 좋습니다 .

응?

이 모든 것에 대한 가장 좋은 설명은 ProGit의 9-5 장, Git Internals-The Refspec ( 또는 github을 통해 )에 있습니다. 구글을 통해 찾기가 놀랍습니다.

먼저 용어를 정리해야합니다. 원격 지점 추적의 경우 일반적으로 다음 3 가지 지점을 알고 있어야합니다.

  1. 원격 저장소의 지점 : refs/heads/branchB다른 저장소 내부
  2. 귀하의 원격 추적 브랜치 : refs/remotes/remoteR/branchB에서 당신 의 repo
  3. 당신의 자신의 지점 : 당신의 레포 refs/heads/branchB내부

의 원격 추적 분기 ( refs/remotes)는 읽기 전용입니다. 직접 수정하지 마십시오. 자신의 브랜치를 수정 한 다음 원격 리포지토리의 해당 브랜치로 푸시합니다. refs/remotes적절한 끌어 오기 또는 가져 오기가 완료 될 때까지 결과가 반영되지 않습니다 . 이러한 구분은 git 맨 페이지에서 이해하기 어려웠습니다. 주로 로컬 브랜치 ( refs/heads/branchB)가 .git/config정의 할 때 원격 추적 브랜치를 "추적"한다고하기 때문 branch.branchB.remote = remoteR입니다.

'refs'를 C ++ 포인터로 생각하십시오. 물리적으로 파일은 SHA 요약을 포함하는 파일이지만 기본적으로 커밋 트리에 대한 포인터입니다. git fetch커밋 트리에 많은 노드를 추가하지만 git이 이동할 포인터를 결정하는 방법은 약간 복잡합니다.

에서 언급 한 바와 같이 다른 답변 , 어느 쪽도 없습니다

    git pull remoteR branchB

...도 아니다

    git fetch remoteR branchB

움직이고 refs/remotes/branches/branchB후자는 확실히 움직일 수 없습니다 refs/heads/branchB. 그러나 둘 다 이동 FETCH_HEAD합니다. (당신은 할 수 있습니다 cat내부 이러한 파일은 .git/. 그들은 변경할 때 볼 수 있습니다) 그리고 git merge참조됩니다 FETCH_HEAD동안 설정 MERGE_ORIG,


an-other-branch합병 할 때 현지인이 확실 합니까?

git fetch origin an-other-branch
git checkout an-other-branch
git merge origin/an-other-branch

다른 설명 :

all the changes from the branch you’re trying to merge have already been merged to the branch you’re currently on.
More specifically it means that the branch you’re trying to merge is a parent of your current branch

if you're ahead of the remote repo by one commit, it's the remote repo that's out of date, not you.

But in your case, if git pull works, that just means you are not on the right branch.


Git pull is actually a combo tool: it runs git fetch (getting the changes) and git merge (merging them with your current copy)

Are you sure you are on the correct branch?


these are the commands:

git fetch origin
git merge origin/somebranch somebranch

if you do this on the second line:

git merge origin somebranch

it will try to merge the local master into your current branch.

The question, as I've understood it, was you fetched already locally and want to now merge your branch to the latest of the same branch.

참고URL : https://stackoverflow.com/questions/2602546/how-do-i-git-fetch-and-git-merge-from-a-remote-tracking-branch-like-git-pu

반응형