最佳答案
在 Linux 上使用 Git 1.8.1.1:
master
book
子模块创建如下:
$ cd /path/to/master
$ git submodule add https://user@bitbucket.org/user/repo.git book
book
子模块是干净的:
$ cd /path/to/master/book/
$ git status
# On branch master
nothing to commit, working directory clean
另一方面,master 显示了 book 子模块的“新提交”:
$ cd /path/to/master/
$ 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)
#
# modified: book (new commits)
#
no changes added to commit (use "git add" and/or "git commit -a")
Git 应该完全忽略子模块目录,这样主目录也是干净的:
$ cd /path/to/master/
$ git status
# On branch master
nothing to commit, working directory clean
文件 master/.gitmodules
内部如下,按照这个 回答:
[submodule "book"]
path = book
url = https://user@bitbucket.org/user/repo.git
ignore = dirty
按照 回答,将 master/.gitmodules
改为以下内容:
[submodule "book"]
path = book
url = https://user@bitbucket.org/user/repo.git
ignore = untracked
编辑 master/.git/config
到以下,根据这个 回答:
[status]
showUntrackedFiles = no
将图书目录添加到主忽略文件:
$ cd /path/to/master/
$ echo book > .gitignore
在主目录中增加了图书目录如下:
$ cd /path/to/master/
$ rm -rf book
$ git clone https://user@bitbucket.org/user/repo.git book
为什么 book
子模块位于 master
存储库下自己的存储库目录中,而 git 却忽略了 book
子模块?即不应显示以下内容:
#
# modified: book (new commits)
#
在主存储库中执行 git status
时如何抑制该消息?
一篇关于 Git 子模块陷阱的文章建议这是一个不恰当的子模块用法?