0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Git】サブモジュール (submodule)が複数ある場合の便利コマンド。git submodule foreach

Posted at

サブモジュール (submodule)が複数ある場合に、各サブモジュールで同じコマンドを実行したい場合にforeachが便利。

$ git submodule foreach <コマンド>

コマンドに記述した処理を各サブモジュールで実行してくれる。


##実例 例えば、(1)deploy, (2)frontend, (3)widget, (4)proto, (5)vuetify-resourcesの5つのサブモジュールがあるプロジェクトで、各サブモジュールの直近1つのコミットを表示した場合。

$ git submodule foreach git log -n 1 --oneline --graph

$ git submodule foreach git log -n 1 --oneline --graph

Entering 'deploy'
* ee83e50 (HEAD -> master, origin/master, origin/deploy, origin/HEAD) [F].env
Entering 'frontend'
*   228a7ff (HEAD, origin/master, origin/HEAD) Merge pull request #42
|\
Entering 'widget'
* 6785b9d (HEAD -> master, origin/master, origin/HEAD) [fix]reply
Entering 'proto'
* 50fc21f (HEAD -> master, origin/master, origin/HEAD) [fix]mini brand
Entering 'vuetify-resources'
*   fbe2572 (HEAD, origin/phone, origin/eugene) Merge pull request #115 from cyber-owl/eugene
|\

Enteringで各サブモジュールに入り、最新コミットを表示している。


##使い道の例

####直近10個のログを表示
$ git submodule foreach git log -n 10 --oneline --graph

####masterからプル
$ git submodule foreach git pull origin/master

####ファイル差分を表示
$ git submodule foreach git diff

など。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?