【发布时间】:2013-01-03 07:26:43
【问题描述】:
背景
在 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 内如下,根据这个answer:
[submodule "book"]
path = book
url = https://user@bitbucket.org/user/repo.git
ignore = dirty
失败的尝试 #2 - 未跟踪
将master/.gitmodules 更改为以下,根据此answer:
[submodule "book"]
path = book
url = https://user@bitbucket.org/user/repo.git
ignore = untracked
尝试失败 #3 - showUntrackedFiles
将master/.git/config 编辑为以下内容,根据此answer:
[status]
showUntrackedFiles = no
尝试失败 #4 - 忽略
将书籍目录添加到主忽略文件中:
$ cd /path/to/master/
$ echo book > .gitignore
失败的尝试 #5 - 克隆
在master中添加book目录如下:
$ 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 的文章表明这是不恰当的子模块用法?
【问题讨论】:
-
如果要将存储库链接到另一个存储库的某个版本并跟踪它,通常会使用子模块。但这似乎不是你想要的。您只想在另一个存储库中使用存储库,而不对其进行跟踪。然后不要将其添加为子模块。
-
@FelixKling,如果您以这种方式添加此类存储库并将其推送到 GitHub,它会为其创建链接而不复制该文件夹的内容吗?
-
@Roland:子模块只是引用其他存储库版本的文件。一旦它们在存储库的本地副本中初始化,它们就会被存储库的实际内容替换。
-
我认为您正在寻找“ignore = all”
-
使用 Git 2.13(2017 年第二季度),您将可以考虑
git config submodule.<name>.active false。见my answer below
标签: git status git-submodules ignore