IT TIP

git 얕은 클론 (clone --depth)이 원격 분기를 놓친다

itqueen 2020. 10. 30. 21:20
반응형

git 얕은 클론 (clone --depth)이 원격 분기를 놓친다


원격 저장소를 복제 한 후 -a 옵션으로 원격 분기를 표시하지 않습니다. 무엇이 문제일까요? 디버그하는 방법? 이 스 니펫에서는 두 개의 원격 분기가 표시되지 않습니다.

$ git clone --depth 1 git://git.savannah.gnu.org/pythonwebkit.git
$ cd pythonwebkit
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
$ git --version
git version 1.8.3.1

다른 컴퓨터에서 동일한 명령을 시도했지만 잘 작동합니다.

$ git clone --depth 1 git://git.savannah.gnu.org/pythonwebkit.git
Receiving objects: 100% (186886/186886), 818.91 MiB | 3.44 MiB/s, done.
$ cd pythonwebkit/
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/debian
  remotes/origin/master
  remotes/origin/python_codegen
$ git --version
git version 1.7.1

다른 저장소를 복제하려고 시도했지만 잘 작동합니다. 이 컴퓨터에서 다시 시도해 볼 수는 있지만 무엇이 잘못되었는지 아는 것이 좋습니다.

어떤 제안이나 힌트도 환영받을 것입니다.

편집 : 답변 요약 : git 버전 1.8.3.2부터 "--depth"및 "--no-single-branch"를 함께 사용하여 이전과 동일한 동작을 수행해야합니다. 이것은 버그 수정으로 간주됩니다.


마지막 개정 이후 마스터 브랜치는 저장소에서 유일한 원격 브랜치입니다 (기본 원격의 HEAD이므로) 동작은 정확합니다.

florianb$ git branch -a
        * master
          remotes/origin/HEAD -> origin/master
          remotes/origin/master

전체 클론은 새로운 (모든) 분기를 제공합니다.

florianb$ git branch -a
        * master
          remotes/origin/HEAD -> origin/master
          remotes/origin/debian
          remotes/origin/master
          remotes/origin/python_codegen

얕은 클론

기술 문서 얕은 설명 으로 인해 " git-clone --depth 20 repo[...] result [s in] 커밋 체인의 길이는 최대 20입니다." 따라서 얕은 클론은 분기 끝에서 요청 된 커밋 깊이를 포함해야합니다.

또한- 옵션 git clone대한 문서는 다음 --single-branch설명합니다.

" --branch옵션에 의해 지정된 단일 분기의 끝으로 이어지는 기록 만 복제 하거나 원격 지점의 기본 분기 HEAD지점을 참조하십시오. 옵션을 사용하여 얕은 복제를 생성 할 때 근처의 기록을 가져 오도록 지정 --depth하지 않는 한 이것이 기본값입니다 --no-single-branch. 모든 지점의 팁. "

따라서 얕은의 클론 ( 깊이 - 옵션은)만을 가져옵니다하나의 지점 (요청한 깊이).


불행히도 두 가지 옵션 ( --depth--single-branch)은 과거에 결함이 있었고 얕은 클론을 사용하면 주어진 기록 다시 쓰기로 인해 발생하는 해결되지 않은 문제가 암시됩니다 (위에 게시 한 링크에서 읽을 수 있음). 이로 인해 전체적으로 특수한 경우 다소 복잡한 동작이 발생합니다.


얕은 클론을 수행 한 후 원격에서 다른 분기체크 아웃 할 수 있습니다 .

  1. 실행 (@jthill에게 감사) :

    git remote set-branches origin '*'
    
  2. 그 후, git fetch -v

  3. 드디어 git checkout the-branch-i-ve-been-looking-for


1 단계는를 편집하여 수동으로 수행 할 수도 있습니다 .git/config.

예를 들어 다음 줄을 다음에서 변경하십시오.

fetch = +refs/heads/master:refs/remotes/origin/master

to (replace master with *):

fetch = +refs/heads/*:refs/remotes/origin/*

From reading the responses and the comment from @jthill, the thing that worked best for me was to use the set-branches option on the git remote command:

$ git clone --depth 1 https://github.com/dogescript/dogescript.git
$ git remote set-branches origin 'remote_branch_name'
$ git fetch --depth 1 origin remote_branch_name
$ git checkout remote_branch_name

This changes the list of branches tracked by the named remote so that we can fetch and checkout just the required branch.

참고URL : https://stackoverflow.com/questions/23708231/git-shallow-clone-clone-depth-misses-remote-branches

반응형