不,您不需要将子模块添加到您的.gitignore
:父级将从您的子模块中看到的是gitlink (a 特别条目,mode 160000 https://stackoverflow.com/a/16581096/6309).
这意味着:在子模块中直接进行的任何更改都需要在父目录中提交。
这样,父目录将记录子模块状态的正确提交:该提交就是上面提到的“gitlink”;
您可以在“中阅读有关该政策的更多信息”git 子模块更新(子模块的真实本质) https://stackoverflow.com/questions/1979167/git-submodule-update/1979194#1979194".
子模块背后的主要思想是基于组件的方法 https://stackoverflow.com/questions/933723/what-is-component-driven-development/933735#933735,您可以在特定提交中引用其他存储库。但是,如果您更改这些子模块中的任何内容,则还需要更新父存储库中的这些引用。
请注意,对于 Git 2.13(2017 年第 2 季度),同时not忽略 gitlink,您仍然可以使用以下方法忽略子模块:
git config submodule.<name>.active false
更多信息请访问 ”忽略 git 子模块的新提交 https://stackoverflow.com/a/43440263/6309".
注意:在 Git 2.15.x/2.16(2018 年第 1 季度)中,忽略子模块更为精确。
"git status --ignored --untracked
”并没有停止在嵌入被忽略的目录中的单独项目的工作树上并列出该其他项目中的文件,而不是仅将目录本身显示为被忽略。
See commit fadb482 https://github.com/git/git/commit/fadb4820c4a0178ce76c24d7b48b7ea70210727a (25 Oct 2017) by Johannes Schindelin (dscho) https://github.com/dscho.
(Merged by Junio C Hamano -- gitster -- https://github.com/gitster in commit da7996a https://github.com/git/git/commit/da7996aaf75fcd58c0fb787c15ee9569140a2f9c, 06 Nov 2017)
status
:不要对排除目录中的子模块感到困惑
我们精心通过exclude
标志到treat_directory()
函数,以便我们可以指示其中的文件在递归时被排除而不是未跟踪。
但我们还没有以同样的方式对待子模块。
正因为如此,git status --ignored --untracked
带有子模块submodule
在 gitignored 中tracked/
将显示子模块
”Untracked files
”部分,例如
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
tracked/submodule/
Ignored files:
(use "git add -f <file>..." to include in what will be committed)
tracked/submodule/initial.t
相反,我们希望它在“Ignored files
”
部分:
On branch master
Ignored files:
(use "git add -f <file>..." to include in what will be committed)
tracked/submodule/