跳转至

Git 忽略子模块的变更

概要: 通过修改子模块配置忽略主库下的子模块变更

创建时间: 2022.10.10 00:34:15

更新时间: 2022.10.10 00:45:31

git子模块变更问题

如果我们对某个git项目(以下称为主库)引用的子模块 git submodule 进行了某些变更,是无法直接通过 git add 命令将其添加到当前主库的暂存区的,因为这部分变更不归主库管理,但是每一次在主库下执行 git status ,又会提示有需要暂存的内容,如下图所示
image.png
如何解决?

解决方法

修改子模块的配置即可,编辑主库下的子模块配置文件,即 .gitmodules
然后在有变更的子模块配置下,添加一行 ignore=dirty 即可,即

Properties
1
2
3
4
5
[submodule "themes/maupassant"]
    path = themes/maupassant
    url = https://github.com/tufu9441/maupassant-hexo.git
    branch = master
    ignore = dirty
最后将 .gitmodules 提交到主库中即可。
image.png

参考