menu
書いてる野郎
orebike@gmail.com
管理しているプロジェクトの一部に別で開発が進行しているプロジェクトを混ぜたい時に使う
まず別管理のプロジェクトを想定して作る
$ mkdir sub1 $ cd sub1 $ git init $ touch s1_index.html $ git add . $ git commit -m "Init sub"
これから管理していくプロジェクトも作る
$ mkdir main1 $ cd main1 $ git init $ touch m1_index.html $ git add . $ git commit -m "Init main"
これで2つのPJができた
main1 の中に sub1 を取り込む。s
という名前で取り込む
$ git submodule add ../sub1 s
s
の中身を見るとしっかり clone されている
$ ls -a s . .. .git s1_index.html
ワークのルートで状態を見ると
$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: .gitmodules new file: s
のようになっている、submodule の管理ファイルと、それが格納されているディレクトリ。 通常gitではディレクトリは管理されないのだが特別に管理されている。
中にファイルがあるにもかかわらず、ファイルは管理に入らないちょっと不思議な状態になる。
とりあえずこのドットファイルも管理するようなのでコミットする
$ git add . $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: .gitmodules new file: s $ git commit -m "Init s in main1"
では sub1を変更してみる。
ファイルを1個追加してコミット。
$ touch s1_index_2.html
tig
を使って add commit。
これで sub1 側が main1 の s
よりも1個進んでいることになる。
つまり main1 の整合性としては、現在の sub1 ではなく、1個前の sub1 でないといけないということになる。
それでは main2 を作って main1 を clone してみる。
$ mkdir main2 $ cd main2 $ git clone ../main1 . Cloning into '.'... done.
確認
$ ls -a . .. .git .gitmodules m1_index.html s とりあえずsまでできている
s
の中身はからっぽ。
こいつをドン。これで取ってこれた。
$ git submodule init $ git submodule update Cloning into 's'... done. Submodule path 's': checked out '6bed616bcff00b0a8ffc68145b32b55b3a356560'
中身を見ると、こうなっていて、1個前のリポジトリ(追加したファイルが無い)が取れてこれているということがわかる
$ ls -a s . .. .git s1_index.html