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 <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)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Add & Commit git init 初始化一个 Git 仓库(repository),即把当前所在目录变成...
    冬絮阅读 4,890评论 0 9
  • 前言:教程来源于Udacity的免费教程-用Git进行版本控制,这里仅是个人的笔记,参考使用。 git add:将...
    地坛公园阅读 1,570评论 0 0
  • 昨天在同事电脑上操作了一把cherry-pick代码,发现很多功能不用,就慢慢忘记了,梳理了下流程图: git c...
    gogoingmonkey阅读 690评论 0 0
  • 本文按照 设置工程、分支与合并、本地操作、分享和更新 四步来简单说一下 Git 基本命令的用法。 Git 命令参考...
    michael_jia阅读 1,290评论 0 3
  • 娱乐圈到底有多深! 娱乐圈有多可怕,内幕可怕,绯闻可怕,欺骗可怕……但那些都是为了达...
    零月半阅读 260评论 0 0