不,您不需要将子模块添加到.gitignore
:父级将从子模块中看到的是gitlink(特殊条目mode 160000
)。
这意味着:直接在子模块中进行的任何更改都需要在父目录中进行提交。
这样,父目录将记录子模块状态的正确提交:该提交是上述的“ gitlink”;
您可以在“ git子模块更新(子模块的真实性质) ”中阅读有关该策略的更多信息。
子模块背后的主要思想是基于组件的方法,您可以在特定提交时引用其他存储库。但是,如果您更改了这些子模块中的任何内容,则还需要更新父存储库中的那些引用。
请注意,在Git 2.13(2017年第二季度)中,尽管不忽略gitlink,您仍然可以使用以下命令忽略子模块:
git config submodule.<name>.active false
请参见“忽略git子模块的新提交”。
注意:对于Git 2.15.x / 2.16(Q1 2018),忽略子模块更为精确。
“ git status --ignored --untracked
”并没有停留在一个单独项目的工作树中,该项目嵌入在被忽略的目录中并在该其他项目中列出了文件,而不仅仅是将目录本身显示为被忽略。
请参阅Johannes Schindelin()的commit fadb482(2017年10月25日)。(由Junio C Hamano合并--在commit da7996a中,2017年11月6日)dscho
gitster
status
:不要被排除目录中的子模块混淆
我们将exclude
标志精心传递给treat_directory()
函数,以便可以指示在递归时将其中的文件排除在外而不是未跟踪。
但是我们还没有以相同的方式对待子模块。
正因为如此,git status --ignored --untracked
有一个子模块
submodule
在gitignoredtracked/
将显示辅助模块中的“中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/