git - 忽略 git 子模块的新提交

标签 git status git-submodules ignore

背景

在 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 - 未追踪

根据 answermaster/.gitmodules 更改为以下内容:

[submodule "book"]
        path = book
        url = https://user@bitbucket.org/user/repo.git
        ignore = untracked

失败的尝试 #3 - showUntrackedFiles

根据 answermaster/.git/config 编辑为以下内容:

[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 的文章暗示这是一个不恰当的子模块使用?

最佳答案

只需运行:

$ git submodule update

这会将子模块还原为旧提交(在父仓库中指定),而不用子模块的最新版本更新父仓库。

关于git - 忽略 git 子模块的新提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14418352/

相关文章:

git - 如何从远程存储库的 URL 确定用户名?

java - git addfilepattern 无法读取我的目录路径

eclipse - BIRT报告框架的发展现状?

git - Maven 发布准备因 Git 子模块而失败

git - git submodule update --init 出错

node.js - 如何使用 npm 脚本将自定义提交消息推送到 github?

javascript - 动态 Javascript/JSON 显示(游戏)服务器状态

javascript - 在netsuite中添加新的事务状态

Git:我可以禁止在状态、差异等中列出 'modified content'/脏子模块条目吗?

git - 如何撤消 'git reset' ?