gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:33:33 24 4
gpt4 key购买 nike

背景

在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com