programing

하위 모듈을 포함하여 repo를 "git cloning"하려면 어떻게 해야 합니까?

starjava 2023. 5. 27. 09:17
반응형

하위 모듈을 포함하여 repo를 "git cloning"하려면 어떻게 해야 합니까?

Git 저장소를 복제하여 하위 모듈도 복제하려면 어떻게 해야 합니까?

중입니다.git clone $REPO_URL빈 하위 모듈 디렉터리만 생성합니다.

2에서는 Git 2.13 버전이 됩니다.--recurse-submodules대신 사용할 수 있습니다.--recursive:

git clone --recurse-submodules -j8 git://github.com/foo/bar.git
cd bar

편자참고사항:-j8할 수 된 성능 한 8개의 병렬로 . 내용은 2.8과 8을 참조하십시오. 참조man git-clone.

1 2까지 (Git 전 1.9터 2.12까)-j플래그는 버전 2.8+에서만 사용할 수 있습니다.

git clone --recursive -j8 git://github.com/foo/bar.git
cd bar

Git 버전 1.6.5 이상에서는 다음을 사용할 수 있습니다.

git clone --recursive git://github.com/foo/bar.git
cd bar

이미 복제된 Repos 또는 이전 Git 버전의 경우 다음을 사용합니다.

git clone git://github.com/foo/bar.git
cd bar
git submodule update --init --recursive

하위 모듈이 채워지기 전에 다음 두 가지 작업을 수행해야 합니다.

git submodule init 
git submodule update

Git 2.23(2019년 3분기): 하위 모듈을 복제하고 최신 버전으로 업데이트하려는 경우:

git clone --recurse-submodules --remote-submodules <repo-URL>

기록된 SHA1에서 복제하려는 경우:

git clone --recurse-submodules <repo-URL>

아래를 참조하십시오.

Git 2.29(2020년 4분기)는 서브모듈 처리에 대한 상당한 최적화를 제공합니다.

Orgad Shaneh()orgads커밋 a462 bee(2020년 9월 6일)를 참조하십시오.
(Junio C Hamano에 의해 합병되었습니다 -- -- 커밋 2ce9d4e, 2020년 9월 18일)

submodule파일 이름 확인 및 개체 ID에 대한 참조 모호성 억제

사인 오프 바이: Orgad Shaneh

collect_changed_submodules()에는 개체 ID(모든 참조의 개체 참조)만 포함됩니다.

리다setup_revisions()전달을 통해 입력이 파일 이름이 아님assume_dashdash,각 기준에 대한 중복 상태를 방지할 수 있습니다.

또한억제를 합니다.refname_ambiguity플래그를 지정하여 각 개체에 대한 파일 시스템 조회를 방지합니다.비슷한 논리는 cat-file, pack-objects 등에서 찾을 수 있습니다.

이 변경 사항은 제 레포에 있는 시간25초에서 6초로 단축합니다.


원답 2010

Joschi가 댓글에서 언급했듯이, 이제는 다음을 지원합니다.--recursive옵션(Git1.6.5 이상)을 선택합니다.

한다면--recursive이 명령을 지정하면 이 명령이 등록된 하위 모듈로 다시 실행되고 내부의 중첩된 하위 모듈이 업데이트됩니다.

init 부분은 Git 하위 모듈 재귀 작업을 참조하십시오.
자세한 내용은 설명을 참조하십시오.

1에서는 Git 전 1.6.5 슈퍼 으로 이 할 수 .–-recursive옵션:

git clone --recursive git://github.com/mysociety/whatdotheyknow.git

git 2.8로 2016 업데이트: "를 사용하여 git 하위 모듈의 다운로드 속도를 높이거나 병렬화하는 방법?"을 참조하십시오.

여러 스레드를 병렬로 사용하여 하위 모듈 가져오기를 시작할 수 있습니다.
예:

git fetch --recurse-submodules -j2

Git 2.23(2019년 3분기)을 사용하면 한 번의 명령으로 하위 모듈을 복제하고 추적 지점에 체크아웃할 수 있습니다!

에비슨()bavison의 커밋 4c69101(2019년 5월 19일)을 참조하십시오.
(주니오 C 하마노에 의해 합병되었습니다 -- -- 커밋 9476094, 2019년 6월 17일)

clone을 더하다--remote-submodules

을 할 때git clone --recurse-submodules▁to▁pass없▁there었습▁previous▁wayly를 통과할 방법이 없었습니다.--remote 묵으로전으로 합니다.git submodule updateSHA-1이 슈퍼 프로젝트에 기록된 것이 아니라 원격 추적 분기에서 하위 모듈을 체크아웃하려는 사용 사례에 대한 명령입니다.

이 패치는 이 상황을 해결합니다.
실제로 지나갑니다.--no-fetchgit submodule update서브모듈이 방금 복제되었기 때문에 원격에서 다시 가져오면 속도가 느려질 뿐입니다.

즉, 다음과 같습니다.

--[no-]remote-submodules:

추적 을 업데이트합니다. Passing SHA-1에 합니다. 합격과 같습니다.--remotegit submodule update.

[빠른 답변]

이 명령을 사용하여 모든 하위 모듈과 함께 repo를 복제할 수 있습니다.

git clone --recursive YOUR-GIT-REPO-URL

또는 프로젝트를 이미 복제한 경우 다음을 사용할 수 있습니다.

git submodule init
git submodule update

[빠른 답변]

상위 레포(일부 하위 모듈 레포 포함)를 복제한 후 다음을 수행합니다.

git submodule update --init --recursive

이 명령을 사용하여 모든 하위 모듈로 repo 복제

git clone --recurse-submodules git@gitlab.staging-host.com:yourproject

모든 하위 모듈의 코드를 업데이트하려면 다음과 같이 하십시오.

git submodule update --recursive --remote

하위 모듈이 분기에 추가된 경우 클론 명령에 하위 모듈을 포함해야 합니다...

git clone -b <branch_name> --recursive <remote> <directory>

사용해 보십시오.

git clone --recurse-submodules

하위 모듈을 상위 프로젝트에 이미 추가했다고 가정하면 하위 모듈 데이터가 자동으로 끌어옵니다.

제 생각에 당신은 3단계로 갈 수 있을 것 같습니다.

git clone
git submodule init
git submodule update

당신은 할 수 .--recursive플래그를 지정합니다.이 매개 변수는 Git가 리포지토리에 정의된 모든 하위 모듈을 복제하도록 강제합니다.

git clone --recursive git@repo.org:your_repo.git

복제 후 하위 모듈 분기가 변경될 수 있으므로 다음 명령을 실행합니다.

git submodule foreach "git checkout master"

늦은 대답

// git CLONE INCLUDE-SUBMODULES ADDRESS DESTINATION-DIRECTORY
git clone --recursive https://USERNAME@bitbucket.org/USERNAME/REPO.git DESTINATION_DIR

한 시간 동안 친구와 빈둥거리면서 말입니다.BitBucket에 대한 관리자 권한이 있더라도 항상 원본 저장소를 복제하고 repo를 소유한 사용자의 암호를 사용합니다.당신이 이 지뢰 트랩과 마주쳤다는 것을 알게 되어 짜증이 납니다.p

git 저장소에 하위 모듈을 포함하려면 이 작업을 수행합니다.

git clone -b <branch_name> --recursive <remote> <directory>

또는

git clone --recurse-submodules

프로젝트 디렉토리에서 이 작업을 수행합니다.

$ git submodule init
$ git submodule update

하위 모듈 병렬 가져오기는 여러 리포지토리를 한 번에 가져올 수 있도록 하여 리포지토리 및 모든 관련 하위 모듈을 가져오는 데 필요한 시간을 줄이는 것을 목표로 합니다.이 작업은 다음과 같은 새 --jobs 옵션을 사용하여 수행할 수 있습니다.

git fetch --recurse-submodules --jobs=4

Git 팀에 따르면, 이를 통해 많은 하위 모듈이 포함된 리포지토리 업데이트 속도를 크게 높일 수 있습니다.new --jobs 옵션 없이 --recurse-submodules를 사용하는 경우 Git는 하위 모듈을 하나씩 가져옵니다.

출처: http://www.infoq.com/news/2016/03/git28-released

새 프로젝트인 경우 다음과 같이 수행할 수 있습니다.

$ git clone --recurse-submodules https://github.com/chaconinc/YourProjectName 

이미 설치되어 있는 경우:

$ cd YourProjectName (for the cases you are not at right directory) 
$ git submodule init
$ git submodule update

GitHub 저장소에 대해서도 같은 문제가 있었습니다.제 계정에 SSH 키가 없습니다.그 과정은

  1. SSH 키 생성
  2. GitHub 계정에 새 SSH 키 추가

다음 하위을 사용하여 할 수 .git clone --recursive YOUR-GIT-REPO-URL)

또는

려달을 합니다.git submodule init그리고.git submodule update이미 복제된 리포지토리에서 하위 모듈을 가져옵니다.

이거 먹어봐요.

git clone -b <branch_name> --recursive <remote> <directory>

분기에 하위 모듈을 추가한 경우 복제 명령에 하위 모듈을 추가해야 합니다.

권장 사항:

# - git submodule init initializes your local configuration file to track the submodules your repository uses, it just sets up the configuration so that you can use the git submodule update command to clone and update the submodules.
git submodule init
# - git submodule update --init initializes your local configuration file and clones the submodules for you, using the commit specified in the main repository.
#   note, command bellow will not pull the right branch -- even if it's in your .gitmodules file, for that you need remote. Likely because it looks at the origin (pointer to remote) in github for the available branches.
#   note, bellow pulls the submodules if you didn't specify them when cloning parent project, ref: https://youtu.be/wTGIDDg0tK8?t=119
git submodule update --init

하위 모듈에 대한 특정 분기가 있는 경우 다음으로 변경합니다.

# - git submodule init initializes your local configuration file to track the submodules your repository uses, it just sets up the configuration so that you can use the git submodule update command to clone and update the submodules.
git submodule init

# - The --remote option tells Git to update the submodule to the commit specified in the upstream repository, rather than the commit specified in the main repository.
#git submodule update --init --remote
git submodule update --init --recursive --remote meta-dataset

테스트 중인 전체 예:

# decided against this because it seems complicated

# - note to clone uutils with its submodule do (cmd not tested):
cd $HOME
git clone --recurse-submodules git@github.com:brando90/ultimate-utils.git

# - git submodules
cd $HOME/diversity-for-predictive-success-of-meta-learning

# - in case it's needed if the submodules bellow have branches your local project doesn't know about from the submodules upstream
git fetch

# -- first repo
# - adds the repo to the .gitmodule & clones the repo
git submodule add -f -b hdb --name meta-dataset git@github.com:brando90/meta-dataset.git meta-dataset/

# - ref for init then update: https://stackoverflow.com/questions/3796927/how-do-i-git-clone-a-repo-including-its-submodules/3796947#3796947
#git submodule init
#git submodule update

# - git submodule init initializes your local configuration file to track the submodules your repository uses, it just sets up the configuration so that you can use the git submodule update command to clone and update the submodules.
git submodule init
# - git submodule update --init initializes your local configuration file and clones the submodules for you, using the commit specified in the main repository.
#   note, command bellow will not pull the right branch -- even if it's in your .gitmodules file, for that you need remote. Likely because it looks at the origin (pointer to remote) in github for the available branches.
#   note, bellow pulls the submodules if you didn't specify them when cloning parent project, ref: https://youtu.be/wTGIDDg0tK8?t=119
git submodule update --init
# - The --remote option tells Git to update the submodule to the commit specified in the upstream repository, rather than the commit specified in the main repository.
#git submodule update --init --remote
git submodule update --init --recursive --remote meta-dataset

# - check we are using the right branch https://stackoverflow.com/questions/74998463/why-does-git-submodule-status-not-match-the-output-of-git-branch-of-my-submodule
git submodule status
cd meta-dataset
git branch  # should show hdb
cd ..

# pip install -r $HOME/meta-dataset/requirements.txt

# -- 2nd repo, simplified commands from above
git submodule add -f -b hdb --name pytorch-meta-dataset git@github.com:brando90/pytorch-meta-dataset.git pytorch-meta-dataset/

git submodule init
git submodule update --init --recursive --remote meta-dataset

# - check it's in specified branch
git submodule status
cd pytorch-meta-dataset
git branch  # should show hdb
cd ..

# pip install -r $HOME/pytorch-meta-dataset/requirements.txt

1.git 하위 모듈 init 2.git 하위 모듈 업데이트

또는 git stash - ugit pull origin 마스터 git stash

하위 모듈이 개인 하위 모듈인 경우 자격 증명 저장소를 사용하여 개인 하위 모듈도 재귀적으로 복제할 수 있습니다.

USER=${GITHUB_ACTOR}
TOKEN=${{ secrets.JEKYLL_GITHUB_TOKEN }}

git config --global credential.helper store
echo "https://${USER}:${TOKEN}@github.com" > ~/.git-credentials

git clone --recurse-submodules -j8 git://github.com/foo/bar.git
cd bar

개인 모듈이 5단계 깊이에 있는 하위 모듈을 복제하는 데 사용합니다.어떻게 작동하는지 보여드리겠습니다.

여기에 이미지 설명 입력

Git 클라이언트에게 --recurse-submodules로 모든 작업을 수행하도록 지시하려면 Git 구성으로 설정할 수 있습니다.

git config submodule.subse true

참조: https://www.git-scm.com/docs/git-config#Documentation/git-config.txt-submodulerecurse

github에서 복제 URL을 복사할 수 있습니다.

그런 다음 git clone --recursive를 사용합니다.

하위 모듈을 포함하여 repo를 "git cloning"하려면 어떻게 해야 합니까?

(이것이 Git에서 중요하다고 생각하기 때문에 독립적인 답변으로 작성했습니다.)

슬프게도, 하지만 그런 경우는 많이 있습니다.less-informed cloners어쨌든 외부를 놓치게 될 것입니다.

  • vcstool(https://github.com/dirk-thomas/vcstool)
  • git-subrepo(https://github.com/ingydotnet/git-subrepo)
  • git links(https://github.com/chronoxor/gil)
  • .gitsvnextmodules)로 됨)smartgit).
  • git-externals(https://github.com/develer-staff/git-externals)
  • git x-modules(https://gitmodules.com/)
  • 등등...

참고:
다음과 같은 프로젝트vcstool,git-subrepo그리고.gil외부 종속성 목록을 저장하는 자체 방법을 사용하고 있으며 복제 작업을 대체하므로 기본적으로 엔드 저장소에.submodules철철철철철철철철철철철철철철철철철철철철
다음은 Git 내부에서 제기된 문제에 대한 몇 가지 설명입니다.
nested submodules detection w/o .gitmodules file:
https://lore.kernel.org/git/1716310675.ruhttps://lore.kernel.org/git/1716310675.20230122233403 @https.ru

백업 과정에서 모든 외부 참조를 미러링(--미러)하기 위해 베어 클론(--베어) + 완전 재귀(--재귀)을 생성할 수 없음:
및 --bare--recursive를 사용하여

그래서 기트를 사용하면 외부 의존성을 완전히 수용할 수 있는 내장 방식이 없습니다.즉, 임의의 Git 저장소를 완전히 백업할 수 있는 단일 방법이 없습니다.

언급URL : https://stackoverflow.com/questions/3796927/how-do-i-git-clone-a-repo-including-its-submodules

반응형