git 忽略子模块中的变更

问题

如下报错,是因为子模块中出现变更导致的。在我们想保留变更,又不想将其添加到子模块的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 ..." to update what will be committed)
  (use "git checkout -- ..." 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 = [email protected]:yelog/hexo-theme-3-hexo.git
[submodule "themes/next"]
        path = themes/next
        url = [email protected]:theme-next/hexo-theme-next.git
[submodule "themes/yilia"]
        path = themes/yilia
        url = [email protected]:litten/hexo-theme-yilia.git
[submodule "themes/material"]
        path = themes/material
        url = [email protected]:viosey/hexo-theme-material.git
[submodule "themes/fluid"]
        path = themes/fluid
        url = [email protected]: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 = [email protected]:fluid-dev/hexo-theme-fluid.git
+       ignore = dirty
(END)

你可能感兴趣的:(git 忽略子模块中的变更)