在 git 存储库中,我设置了 .gitmodules 文件以引用 github 存储库:
[submodule "src/repo"]
path = src/repo
url = repourl
Run Code Online (Sandbox Code Playgroud)
当我在这个 repo 上“git status”时,它显示:
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/repo (new commits)
Run Code Online (Sandbox Code Playgroud)
如果我 cd 进入 src/repo 和 repo 上的 git status,它说没有什么可提交的。
为什么我的顶级 git repo 抱怨?
yae*_*shi 53
这是因为应该为每个子模块检出 Git 记录哪些提交(不是分支或标签,仅用 SHA-1 哈希表示的一个提交)。如果您更改子模块目录中的某些内容,Git 将检测到它并敦促您在顶级存储库中提交这些更改。
git diff
在顶级存储库中运行以显示实际改变了 Git 认为的内容。如果您已经在子模块中进行了一些提交(因此子模块中的“干净”),它会报告子模块的哈希更改。
$ git diff
diff --git a/src/repo b/src/repo
index b0c86e2..a893d84 160000
--- a/src/repo
+++ b/src/repo
@@ -1 +1 @@
-Subproject commit b0c86e28675c9591df51eedc928f991ca42f5fea
+Subproject commit a893d84d323cf411eadf19569d90779610b10280
Run Code Online (Sandbox Code Playgroud)
否则,它会显示-dirty
无法在顶级存储库中暂存或提交的哈希更改。 git status
还声称子模块具有未跟踪/修改的内容。
$ git diff
diff --git a/src/repo b/src/repo
--- a/src/repo
+++ b/src/repo
@@ -1 +1 @@
-Subproject commit b0c86e28675c9591df51eedc928f991ca42f5fea
+Subproject commit b0c86e28675c9591df51eedc928f991ca42f5fea-dirty
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: src/repo (untracked content)
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)
要更新子模块应检出哪些提交记录,除了提交子模块中的更改外,您还需要 git commit 子模块:
git add src/repo
Run Code Online (Sandbox Code Playgroud)
Zak*_*Zak 51
我刚刚遇到了同一类问题,并且能够在已接受答案的评论部分使用@AugustinAmenabar提供的解决方案。我的设置有点复杂,所以我添加了--recursive
标志以使所有依赖项都是最新的。
git submodule update --recursive src/repo