문제

우리는 GIT 하위 모듈을 사용하여 우리가 개발 한 다른 많은 라이브러리에 의존하는 몇 가지 대규모 프로젝트를 관리합니다. 각 라이브러리는 하위 모듈로 종속 프로젝트로 가져온 별도의 리포입니다. 개발 중에, 우리는 종종 모든 종속 하위 모듈의 최신 버전을 잡고 싶어합니다.

git 은이 작업을 수행하기위한 명령이 내장되어 있습니까? 그렇지 않은 경우 Windows 배치 파일 또는 이와 유사한 것은 어떻습니까?

도움이 되었습니까?

해결책

그렇다면 처음 당신은 당신이 사용해야하는 저장소를 체크 아웃합니다 --init 첫 번째:

git submodule update --init --recursive

을 위한 git 1.8.2 또는 옵션 이상 --remote 원격 분기의 최신 팁 업데이트를 지원하기 위해 추가되었습니다.

git submodule update --recursive --remote

이것은 .gitmodules 또는 .git/config 파일 (어떤 경우에는 기본값이 Origin/Master입니다.이 경우 다른 답변 중 일부는 작동합니다).

을 위한 git 1.7.3 또는 그 이상으로 사용할 수 있습니다 (그러나 아래의 업데이트가 여전히 적용되는 내용에 대한 아래의 Gotchas) : :

git submodule update --recursive

또는:

git pull --recurse-submodules

서브 모듈을 최신으로 끌어 당기려면 리포지토리가 포인트가 무엇을 가리키는지를 강조합니다.

보다 git-submodule (1) 자세한 내용은

다른 팁

서브 모듈에 대한 물건을 서브 모듈 리포지토리로 가져와야하는 경우

git pull --recurse-submodules

기능 Git은 1.7.3에서 처음 배운 것입니다.

그러나 이것은 하위 모듈에서 적절한 커밋 (마스터 저장소가 가리키는 것)을 확인하지 않습니다.

서브 모듈에서 적절한 커밋을 확인하려면 사용한 후 업데이트해야합니다.

git submodule update --recursive --remote

다음 명령을 실행하는 Init에서 :

git submodule update --init --recursive

Git Repo 디렉토리 내에서 나에게 가장 잘 작동합니다.

이것은 서브 모듈을 포함한 모든 최신 최신을 가져옵니다.

설명했다

git - the base command to perform any git command
    submodule - Inspects, updates and manages submodules.
        update - Update the registered submodules to match what the superproject
        expects by cloning missing submodules and updating the working tree of the
        submodules. The "updating" can be done in several ways depending on command
        line options and the value of submodule.<name>.update configuration variable.
            --init without the explicit init step if you do not intend to customize
            any submodule locations.
            --recursive is specified, this command will recurse into the registered
            submodules, and update any nested submodules within.

이 후에는 그냥 실행할 수 있습니다.

git submodule update --recursive

Git Repo 디렉토리 내에서 나에게 가장 잘 작동합니다.

이것은 서브 모듈을 포함한 모든 최신 최신을 가져옵니다.

참고 : 이것은 2009 년부터 좋았을 수도 있지만 지금은 더 나은 옵션이 있습니다.

우리는 이것을 사용합니다. 라고 불린다 git-pup:

#!/bin/bash
# Exists to fully update the git repo that you are sitting in...

git pull && git submodule init && git submodule update && git submodule status

적절한 빈 디렉토리 (/usr/local/bin)에 넣으십시오. Windows에있는 경우 구문을 수정하여 작동하도록해야 할 수도 있습니다. :)

업데이트:

원래 저자의 모든 하위 모듈의 모든 머리를 끌어 당기는 것에 대한 원래 저자의 의견에 응답하여 좋은 질문입니다.

나는 그것을 확신합니다 git 내부적으로 이에 대한 명령이 없습니다. 그렇게하려면 서브 모듈의 머리가 실제로 무엇인지 식별해야합니다. 그것은 말하는 것만 큼 간단 할 수 있습니다 master 최신 지점 등입니다 ...

이어서 다음을 수행하는 간단한 스크립트를 만듭니다.

  1. 확인하다 git submodule status "수정 된"리포지토리 용. 출력 라인의 첫 번째 문자는 이것을 나타냅니다. 하위 레포가 수정되면 계속 진행하고 싶지 않을 수 있습니다.
  2. 나열된 각 repo에 대해 CD는 디렉토리에 들어가고 실행됩니다. git checkout master && git pull. 오류를 확인하십시오.
  3. 결국, 나는 당신이 서브 모듈의 현재 상태를 나타 내기 위해 사용자에게 디스플레이를 인쇄하는 것이 좋습니다.

나는이 스타일이 실제로 git submodules를 위해 설계된 것이 아니라고 언급하고 싶습니다. 일반적으로 "LibraryX"는 버전 "2.32"라고 말하고 "업그레이드"라고 말할 때까지 그 길을 유지합니다.

즉, 어떤 의미에서, 설명 된 스크립트로 무엇을하고 있지만, 더 자동으로. 치료가 필요합니다!

Update 2:

Windows 플랫폼에있는 경우 Python을 사용하여 스크립트를 구현하여 이러한 영역에서는 매우 능력이 있습니다. Unix/Linux에 있다면 Bash 스크립트 만 제안합니다.

설명이 필요하십니까? 의견을 게시하십시오.

Henrik은 올바른 길을 가고 있습니다. 'foreach'명령은 임의의 쉘 스크립트를 실행할 수 있습니다. 최신작을 당기는 두 가지 옵션은

git submodule foreach git pull origin master

그리고,

git submodule foreach /path/to/some/cool/script.sh

그것은 모든 것을 반복 할 것입니다 초기화 하위 모듈 및 주어진 명령을 실행하십시오.

다음은 Windows에서 저를 위해 일했습니다.

git submodule init
git submodule update

편집하다:

의견에서 지적되었다 (by Philfreo ) 최신 버전이 필요합니다. 최신 버전에 있어야하는 중첩 하위 모듈이있는 경우 :

git submodule foreach --recursive git pull

----- 아래의 구식 의견 ----

이것이 공식적인 방법이 아닌가?

git submodule update --init

나는 매번 그것을 사용합니다. 지금까지 문제가 없습니다.

편집하다:

방금 사용할 수 있다는 것을 알았습니다.

git submodule foreach --recursive git submodule update --init 

또한 모든 서브 모듈, 즉 종속성을 재귀 적으로 당길 것입니다.

하위 모듈의 기본 지점이 ~ 아니다 master, 이것이 전체 git 하위 모듈 업그레이드를 자동화하는 방법입니다.

git submodule init
git submodule update
git submodule foreach 'git fetch origin; git checkout $(git rev-parse --abbrev-ref HEAD); git reset --hard origin/$(git rev-parse --abbrev-ref HEAD); git submodule update --recursive; git clean -dfx'

처음으로

복제 및 초기 하위 모듈

git clone git@github.com:speedovation/kiwi-resources.git resources
git submodule init

쉬다

개발 중에 하위 모듈을 당기고 업데이트하십시오

git pull --recurse-submodules  && git submodule update --recursive

git 하위 모듈을 최신 커밋으로 업데이트하십시오

git submodule foreach git pull origin master

선호하는 방법은 아래에 있어야합니다

git submodule update --remote --merge

참고 : 마지막 두 명령에는 동일한 동작이 있습니다

나는 이것이 어떤 버전의 git가 작동하는지 잘 모르겠지만, 그것이 당신이 찾고있는 것입니다.

git submodule update --recursive

나는 그것을 함께 사용합니다 git pull 루트 저장소도 업데이트하려면 :

git pull && git submodule update --recursive

보다 http://lists.zerezo.com/git/msg674976.html -트랙 매개 변수를 소개합니다

위의 답변은 좋지만 우리는 이것을 더 쉽게 만들기 위해 git-hooks를 사용하고 있었지만 git 2.14, 당신은 설정할 수 있습니다 git config submodule.recurse git 저장소로 당기면 서브 모듈이 업데이트 될 수 있도록합니다.

이것은 지점에있는 경우 모든 서브 모듈 변경을 밀어 넣는 부작용이 있지만, 이미 그 행동이 필요하다면 이미 작업을 수행 할 수 있습니다.

다음을 사용하여 수행 할 수 있습니다.

git config submodule.recurse true

창문 용 2.6.3:

git submodule update --rebase --remote

나는 적응하여 이것을했다 가호아'에스 위의 답변:

그것을 git과 통합하십시오 [alias] ...

부모 프로젝트에 이와 같은 것이 있다면 .gitmodules:

[submodule "opt/submodules/solarized"]
    path = opt/submodules/solarized
    url = git@github.com:altercation/solarized.git
[submodule "opt/submodules/intellij-colors-solarized"]
    path = opt/submodules/intellij-colors-solarized
    url = git@github.com:jkaving/intellij-colors-solarized.git

.gitconfig 안에 이와 같은 것을 추가하십시오

[alias]
    updatesubs = "!sh -c \"git submodule init && git submodule update && git submodule status\" "

그런 다음 하위 모듈을 업데이트하려면 실행하십시오.

git updatesubs

나는있다 예시 그것의 내 환경 설정 repo.

다음은 모든 GIT 저장소에서 하위 모듈이든 상관없이 모든 GIT 리포지토리에서 가져 오는 명령 줄입니다.

ROOT=$(git rev-parse --show-toplevel 2> /dev/null)
find "$ROOT" -name .git -type d -execdir git pull -v ';'

상단 GIT 저장소에서 실행하면 교체 할 수 있습니다. "$ROOT" ~ 안으로 ..

지금해야 할 일은 간단합니다 git checkout

이 글로벌 구성을 통해 활성화하십시오. git config --global submodule.recurse true

레포의 최상위 레벨에서 :

git submodule foreach git checkout develop
git submodule foreach git pull

이것은 모든 지점을 전환하여 최신 버전을 개발하고 당깁니다.

이 작업을 수행하려면 스크립트를 작성해야한다고 생각합니다. 솔직히 말해서, 나는 당신이 사용할 수 있도록 파이썬을 설치할 수 있습니다. os.walk 에게 cd 각 디렉토리에 적절한 명령을 발행하십시오. Python 또는 일부 스크립팅 언어를 사용하면 배치 이외의 다른 스크립팅 언어를 사용하면 스크립트를 수정할 필요가없는 서브 프로젝트를 쉽게 추가/제거 할 수 있습니다.

비고 : 너무 쉬운 방법은 아니지만 실행 가능하며 고유 한 장점이 있습니다.

하나만 복제하고 싶다면 HEAD 저장소의 개정 및 만 HEAD모든 ITS 하위 모듈 (즉, "트렁크"를 체크 아웃) 중 하나 인 다음 다음을 사용할 수 있습니다. 루아 스크립트. 때때로 간단한 명령 git submodule update --init --recursive --remote --no-fetch --depth=1 복귀 할 수없는 결과를 초래할 수 있습니다 git 오류. 이 경우 하위 디렉토리를 정리해야합니다. .git/modules 디렉토리 및 클론 하위 모듈 수동으로 사용합니다 git clone --separate-git-dir 명령. 유일한 복잡성은 알아내는 것입니다 URL, 경로 .git 슈퍼 프론트 트리에서 하위 모듈 및 하위 모듈의 경로의 디렉토리.

비고 : 스크립트는 만 테스트됩니다 https://github.com/boostorg/boost.git 저장소. 그것의 특성 : 동일한 호스트에서 호스팅 된 모든 서브 모듈과 .gitmodules 상대 만 포함합니다 URL에스.

-- mkdir boost ; cd boost ; lua ../git-submodules-clone-HEAD.lua https://github.com/boostorg/boost.git .
local module_url = arg[1] or 'https://github.com/boostorg/boost.git'
local module = arg[2] or module_url:match('.+/([_%d%a]+)%.git')
local branch = arg[3] or 'master'
function execute(command)
    print('# ' .. command)
    return os.execute(command)
end
-- execute('rm -rf ' .. module)
if not execute('git clone --single-branch --branch master --depth=1 ' .. module_url .. ' ' .. module) then
    io.stderr:write('can\'t clone repository from ' .. module_url .. ' to ' .. module .. '\n')
    return 1
end
-- cd $module ; git submodule update --init --recursive --remote --no-fetch --depth=1
execute('mkdir -p ' .. module .. '/.git/modules')
assert(io.input(module .. '/.gitmodules'))
local lines = {}
for line in io.lines() do
    table.insert(lines, line)
end
local submodule
local path
local submodule_url
for _, line in ipairs(lines) do
    local submodule_ = line:match('^%[submodule %"([_%d%a]-)%"%]$')
    if submodule_ then
        submodule = submodule_
        path = nil
        submodule_url = nil
    else
        local path_ = line:match('^%s*path = (.+)$')
        if path_ then
            path = path_
        else
            submodule_url = line:match('^%s*url = (.+)$')
        end
        if submodule and path and submodule_url then
            -- execute('rm -rf ' .. path)
            local git_dir = module .. '/.git/modules/' .. path:match('^.-/(.+)$')
            -- execute('rm -rf ' .. git_dir)
            execute('mkdir -p $(dirname "' .. git_dir .. '")')
            if not execute('git clone --depth=1 --single-branch --branch=' .. branch .. ' --separate-git-dir ' .. git_dir .. ' ' .. module_url .. '/' .. submodule_url .. ' ' .. module .. '/' .. path) then
                io.stderr:write('can\'t clone submodule ' .. submodule .. '\n')
                return 1
            end
            path = nil
            submodule_url = nil
        end
    end
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top