質問

私たちは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 以上の場合は、使用できます(ただし、以下のアップデートはまだ適用されるものについての落とし穴です):

git submodule update --recursive

または:

git pull --recurse-submodules

サブモジュールを、リポジトリが指すものの代わりに最新のコミットにプルする場合。

git-submodule(1)詳細について

他のヒント

サブモジュール用のものをサブモジュールリポジトリにプルする必要がある場合は、

を使用します
git pull --recurse-submodules
  

1.7.3で最初に学習した機能git。

ただし、これはサブモジュールで適切なコミット(マスターリポジトリが指すもの)をチェックアウトしません

サブモジュールで適切なコミットをチェックアウトするには、使用してプルした後に更新する必要があります

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

適切なbinディレクトリ(/ usr / local / bin)に置きます。 Windowsの場合、動作させるために構文を変更する必要があるかもしれません:)

更新:

すべてのサブモジュールのすべてのHEADを取り込むことについての、元の作者によるコメントに対する回答-これは良い質問です。

git にはこのためのコマンドが内部にないことを確信しています。これを行うには、サブモジュールの実際のHEADを識別する必要があります。これは、 master が最新のブランチなどであると言うのと同じくらい簡単です。

これに続いて、次のことを行う簡単なスクリプトを作成します。

    &lt; modified&quot;の
  1. gitサブモジュールステータスを確認します。リポジトリ。出力行の最初の文字はこれを示しています。サブレポジトリが変更された場合、続行することはできません。
  2. リストされた各リポジトリについて、そのディレクトリにcdして、 git checkout master&amp;&amp;を実行します。 git pull 。エラーを確認します。
  3. 最後に、サブモジュールの現在のステータスを示すためにユーザーにディスプレイを印刷することをお勧めします。おそらく、すべてを追加してコミットするように促しますか?

このスタイルは、実際にはgitサブモジュールが設計されたものではないことに言及したいと思います。通常、&quot; LibraryX&quot;と言います。バージョンは「2.32」です。そして、「アップグレード」を指示するまでそのままです。

それは、ある意味では、記述されたスクリプトを使用して行うことですが、より自動的に行われます。注意が必要です!

更新2:

Windowsプラットフォームを使用している場合は、Pythonを使用してスクリプトを実装することを検討することをお勧めします。これらの領域では非常に優れているからです。 UNIX / Linuxを使用している場合は、bashスクリプトをお勧めします。

説明が必要ですか?コメントを投稿してください。

ヘンリックは正しい軌道に乗っています。 「foreach」コマンドは、任意のシェルスクリプトを実行できます。最新のものを取得する2つのオプションは次のとおりです。

git submodule foreach git pull origin master

そして

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

すべての初期化サブモジュールを反復処理し、指定されたコマンドを実行します。

以下はWindowsでうまくいきました。

git submodule init
git submodule update

編集

コメントでは、( philfreo によって)最新バージョンが必要であると指摘されました。最新バージョンにする必要があるネストされたサブモジュールがある場合:

git submodule foreach --recursive git pull

-----以下の古いコメント-----

これは公式の方法ではありませんか?

git submodule update --init

毎回使用しています。今のところ問題はありません。

編集:

使用できることがわかりました:

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

また、すべてのサブモジュール、つまり依存関係を再帰的にプルします。

サブモジュールのデフォルトのブランチが not 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

注:最後の2つのコマンドの動作は同じです

どのバージョンのgitが機能しているかはわかりませんが、探しているのはそれです:

git submodule update --recursive

ルートリポジトリの更新にも git pull で使用します:

git pull && git submodule update --recursive

上記の答えは良いですが、これを簡単にするためにgitフックを使用していましたが、 git 2.14 では、 git config submodule.recurse をtrueにすると、サブモジュールをプルしたときに更新できるようになりますgitリポジトリへ。

これは、ブランチ上にあるすべてのサブモジュールの変更をプッシュするという副作用がありますが、すでにその動作が必要な場合は、これで仕事ができます。

次を使用して実行できます:

git config submodule.recurse true

Windows用Git 2.6.3

gitサブモジュールの更新--rebase --remote

gahooa 上記の回答

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

がありますmy 環境設定リポジトリ

サブモジュールであるかどうかに関係なく、すべてのgitリポジトリからプルするコマンドラインは次のとおりです。

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

トップgitリポジトリで実行している場合、&quot; $ ROOT&quot; に置き換えることができます。

今必要なのは、簡単な git checkout

だけです。

このグローバル設定を使用して、必ず有効にしてください: git config --global submodule.recurse true

レポジトリの最上位から:

git submodule foreach git checkout develop
git submodule foreach git pull

これにより、すべてのブランチが最新の開発およびプルに切り替えられます

これを行うには、スクリプトを作成する必要があると思います。正直に言うと、Pythonをインストールして、各ディレクトリに os.walk を使用して cd を実行し、適切なコマンドを発行できるようにします。バッチ以外のPythonまたはその他のスクリプト言語を使用すると、スクリプトを変更せずにサブプロジェクトを簡単に追加/削除できます。

注意:あまり簡単な方法ではありませんが、実行可能であり、独自の長所があります。

リポジトリの HEAD リビジョンのみとそのすべてのサブモジュールの HEAD のみのクローンを作成する場合(つまり、「トランク」をチェックアウトする場合)、次の Lua スクリプトを使用します。時々、単純なコマンド 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