背景
在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
问题
另一方面,主分支显示书籍子模块有“新提交”:
$ 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
尝试失败 #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
第三次尝试失败 - showUntrackedFiles
根据这个答案,编辑master/.git/config
如下:
[status]
showUntrackedFiles = no
尝试失败 #4 - 忽略
将book目录添加到主要的忽略文件中:
$ cd /path/to/master/
$ echo book > .gitignore
第五次失败尝试-克隆
按照以下方式将book目录添加到主分支中:
$ cd /path/to/master/
$ rm -rf book
$ git clone https://user@bitbucket.org/user/repo.git book
问题
如何使book
子模块位于主存储库下的自己的存储库目录中,同时让git忽略book
子模块?也就是说,不应该显示以下内容:
#
# modified: book (new commits)
#
如何在主代码库中执行 git status
命令时抑制该消息?
一篇关于Git子模块陷阱的文章指出这是不适当的子模块使用方式吗?
git config submodule.<name>.active false
。请参见下面的答案。 - VonC