メインのリポジトリをクローンと同時に、サブモジュールの取得をすると
以下の様なエラーが発生した。
[same@Server1 ~]$ git clone --recursive https://my.gitlab.net/hoge/oya.git
Cloning into 'oya'...
remote: Counting objects: 2348, done.
remote: Compressing objects: 100% (1492/1492), done.
remote: Total 2348 (delta 782), reused 2167 (delta 729)
Receiving objects: 100% (2348/2348), 100.50 MiB | 20.35 MiB/s, done.
Resolving deltas: 100% (782/782), done.
Submodule 'app/Model' (https://my.gitlab.net/hoge/kodomo.git) regist ered for path 'app/Model'
Cloning into '/home/same/oya/app/Model'...
error: no such remote ref d6b7d3810643395618a9f2e741aac56a8fe607e0
Fetched in submodule path 'app/Model', but it did not contain d6b7d3810643395618 a9f2e741aac56a8fe607e0. Direct fetching of that commit failed.
[same@Server1 ~]$ git submodule status
-d6b7d3810643395618a9f2e741aac56a8fe607e0 app/Model
どうやら、サブモジュールのリポジトリに存在しないコミットIDを見ている。
git submodule updateも何もかも効かないので、一度、サブモジュールを削除して追加したら解決した。
手順
①.gitmodules, .git/config から該当する行を削除後
他のサブモジュールが無いなら.gitmodulesは消した方が良いようです。
私の場合は、サブモジュールが1つだったので消しました。
②git rm --cached app/Model
rm 'app/Model'
③念のため、コミット&プッシュ
git commit -m "Del: delete submodule"
1 file changed, 1 deletion(-)
delete mode 160000 app/Model
git push
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 286 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
To https://my.gitlab.net/hoge/oya.git
b5490ab..5130d53 master -> master
④再度、サブモジュールとして追加(今回は、ブランチ指定)
git submodule add -b release/1.1.0 https://my.gitlab.net/hoge/kodomo.git app/Model
Cloning into '/home/same/oya/app/Model'...
remote: Counting objects: 339, done.
remote: Compressing objects: 100% (274/274), done.
remote: Total 339 (delta 142), reused 181 (delta 59)
Receiving objects: 100% (339/339), 1.85 MiB | 2.93 MiB/s, done.
Resolving deltas: 100% (142/142), done.
確認!
git submodule status
0ee4aa63725b58603ee9b4f9be16700c1708a182 app/Model (heads/release/1.1.0)
新しいコミットIDになった!
⑤最後に、コミット&プッシュ
git commit -m "Add: add submodule"
1 file changed, 1 insertion(+)
create mode 160000 app/Model
git push
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 309 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
To https://my.gitlab.net/hoge/oya.git
5130d53..bbf1631 master -> master
⑥もっかい、クローンと同時に、サブモジュールの取得
git clone --recursive https://my.gitlab.net/hoge/oya.git oya2
Cloning into 'oya2'...
remote: Counting objects: 2354, done.
remote: Compressing objects: 100% (1498/1498), done.
remote: Total 2354 (delta 786), reused 2167 (delta 729)
Receiving objects: 100% (2354/2354), 100.50 MiB | 22.63 MiB/s, done.
Resolving deltas: 100% (786/786), done.
Submodule 'app/Model' (https://my.gitlab.net/hoge/kodomo.git) regist ered for path 'app/Model'
Cloning into '/home/same/oya2/app/Model'...
Submodule path 'app/Model': checked out '0ee4aa63725b58603ee9b4f9be16700c1708a18 2'
一件落着…原因が不明→わかりました!
今回のケースでは、サブモジュール追加時に、ブランチを指定しています。
リリースブランチは、残しておく運用をしているのですが
誤って一度消してしまった様で、同じブランチ名だが実は枝が違うものになっていたようです。