美文网首页程序员
git 忽略子模块中的变更

git 忽略子模块中的变更

作者: 思考的猩猩 | 来源:发表于2019-12-11 23:30 被阅读0次

问题

如下报错,是因为子模块中出现变更导致的。在我们想保留变更,又不想将其添加到子模块的gitignore文件中的时候,应该怎么办呢?

➜  expwdx.github.io git:(gh-pages) git status
On branch gh-pages
Your branch is up to date with 'origin/gh-pages'.

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)
  (commit or discard the untracked or modified content in submodules)

    modified:   themes/fluid (untracked content)

解决办法

如下图所示,在gitmodule文件中的对应子模块配置中增加ignore = dirty即可。

  • vim .gitmodule
[submodule "themes/3-hexo"]
        path = themes/3-hexo
        url = git@github.com:yelog/hexo-theme-3-hexo.git
[submodule "themes/next"]
        path = themes/next
        url = git@github.com:theme-next/hexo-theme-next.git
[submodule "themes/yilia"]
        path = themes/yilia
        url = git@github.com:litten/hexo-theme-yilia.git
[submodule "themes/material"]
        path = themes/material
        url = git@github.com:viosey/hexo-theme-material.git
[submodule "themes/fluid"]
        path = themes/fluid
        url = git@github.com:fluid-dev/hexo-theme-fluid.git
        ignore = dirty
  • git diff
diff --git a/.gitmodules b/.gitmodules
index ad752a7..de11a01 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -13,3 +13,4 @@
 [submodule "themes/fluid"]
        path = themes/fluid
        url = git@github.com:fluid-dev/hexo-theme-fluid.git
+       ignore = dirty
(END)

相关文章

网友评论

    本文标题:git 忽略子模块中的变更

    本文链接:https://www.haomeiwen.com/subject/tsqzgctx.html