1
1

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 5 years have passed since last update.

git submodule を使った時のmemo

Posted at

経緯

gitに1つのプロジェクトを2つの別々のプロジェクトとして登録することになった。
しかしリポジトリをビルドするときには2つのリポジトリを1つのプロジェクトとして両方の資材が必要なので、gitのsubmoduleという機能を使ってみた。

使ってみた

まずはそれぞれをリポジトリに登録。(gitbucket使用)

そしてrepo1の中で

$ git submodule add http://localhost:8080/git/hogehoge/repo2.git repo2

これでrepo2はrepo1の中でsubmoduleとして扱ってくれる。

想像と違った

使ってみてちょっと違うな、と思った。
まず、submodule登録した場所へ移動するとそこはrepo2の中なわけで、そこでrepo2に対してadd/commit/push/pull等できるのだが、この変更がrepo1でもnew commits扱いになる。
なぜならsubmodule登録した時点のrepo2のコミットハッシュ値がrepo1側で保持されていて、これと違うとsubmoduleが更新されているという扱いになるからだ。

git submodule update

というコマンドがあるが、これはrepo1で保持しているコミットハッシュ値に資材を更新しますよ、という意味のような動作になるので、このupdateコマンドでsubmoduleが最新に更新されると勘違いしていた私は少しだけ嵌った。。。

git statusしたらsubmoduleにnew commitsと出るときは、これもadd/commit/pushしてあげないとだめ。
もしくは無視してsubmoduleをつねに手動でpullし続けるか。

あと、jenkinsでsubmoduleを使ったリポジトリをビルドしようとしたら、submoduleに対する認証ができなくて詰んだ。
少し調べたが、Git pluginのバグか?くらいの情報しか見つけられなかった。

結論

使えなくはないができることなら使いたくない。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?