背景
在 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 应该完全忽略子模块目录,这样 master 也是干净的:
$ cd /path/to/master/
$ git status
# On branch master
nothing to commit, working directory clean
失败的尝试 #1 - 脏
根据此答案,文件内部master/.gitmodules
如下:
[submodule "book"]
path = book
url = https://user@bitbucket.org/user/repo.git
ignore = dirty
失败的尝试 #2 - 未跟踪
根据此答案更改master/.gitmodules
为以下内容:
[submodule "book"]
path = book
url = https://user@bitbucket.org/user/repo.git
ignore = untracked
尝试失败 #3 - showUntrackedFiles
根据this answer编辑master/.git/config
为以下内容:
[status]
showUntrackedFiles = no
失败的尝试 #4 - 忽略
将 book 目录添加到主忽略文件中:
$ cd /path/to/master/
$ echo book > .gitignore
失败的尝试 #5 - 克隆
将 book 目录添加到 master 中,如下所示:
$ 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 submodule pitfalls的文章表明这是不适当的子模块使用?