我有一个带有子模块的 Git 存储库,在子模块存储库中创建新的提交后,我注意到当我在父存储库中运行
git submodule status
时,父存储库中子模块的提交 ID 自动更新。
$ git submodule update --init sub-repo
Submodule 'sub-repo' ([email protected]:xxx/sub-repo.git) registered for path 'sub-repo'
Cloning into '/Users/xxx/demo2/main-repo/sub-repo'...
Submodule path 'sub-repo': checked out 'b39a213109219d943efd5f0d50a765344760a5cd'
$ git submodule status
b39a213109219d943efd5f0d50a765344760a5cd sub-repo (heads/main)
$ cd sub-repo
$ touch file2
$ git add .
$ git commit -m "add file2"
[detached HEAD 8bfc422] add file2
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file2
$ cd ..
$ git submodule status
+8bfc4220fbd6c941e493bfa790d049c7169514f9 sub-repo (heads/main-1-g8bfc422) # commit ID changed?
在子模块中进行新的提交后,父存储库中子模块的提交 ID 是否会自动更新?如果是这样,是什么触发了此更新?
$ git submodule status
+8bfc4220fbd6c941e493bfa790d049c7169514f9 sub-repo (heads/main-1-g8bfc422)
状态开头有
+
这意味着当前签出的子模块提交与超级项目索引中找到的 SHA-1 不匹配。您应该更新超级项目:
$ git add sub-repo
$ git commit -m "Update submodule sub-repo"