git submodule
git
書き方
git submodule update --init --recursive別のリポジトリをコミット一つに固定して自分のリポジトリ内に置きます。普通にクローンするとフォルダーは空で、update --initが必要ですし、親が押さえているのはブランチではなくコミットです。
よく使うオプション
| オプション | 意味 |
|---|---|
| add <url> <path> | pin another repository at a path |
| update --init | fill in a submodule folder that a clone left empty |
| --recursive | go into submodules of submodules |
| update --remote | move the pin to the tip of the tracked branch |
| status | the commit each submodule sits at |
| deinit <path> | unregister it |
| foreach <cmd> | run a command in each one |
例
git submodule update --init --recursivethe command that fills empty submodule folders after a clone
git submodule add https://github.com/x/lib.git vendor/libadds a dependency as a submodule
git submodule update --remoteupdates the pinned commit to the branch tip
取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. git submodule は何をしますか。
別のリポジトリをコミット一つに固定して自分のリポジトリ内に置きます。普通にクローンするとフォルダーは空で、update --initが必要ですし、親が押さえているのはブランチではなくコミットです。
Q. どう打ちますか。
git submodule update --init --recursive — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは7個です。全部は man git にあります。このコマンドはgitの仲間です。
関連するコマンド
man ページ: man git-submodule