Git diff says subproject is dirty

I have just run a git diff, and I am getting the following output for all of my approx 10 submodules

diff --git a/.vim/bundle/bufexplorer b/.vim/bundle/bufexplorer
--- a/.vim/bundle/bufexplorer
+++ b/.vim/bundle/bufexplorer
@@ -1 +1 @@
-Subproject commit 8c75e65b647238febd0257658b150f717a136359
+Subproject commit 8c75e65b647238febd0257658b150f717a136359-dirty

What does this mean? How do I fix it?


As mentioned in Mark Longair's blog post Git Submodules Explained,

Versions 1.7.0 and later of git contain an annoying change in the behavior of git submodule.
Submodules are now regarded as dirty if they have any modified files or untracked files , whereas previously it would only be the case if HEAD in the submodule pointed to the wrong commit.

The meaning of the plus sign ( + ) in the output of git submodule has changed, and the first time that you come across this it takes a little while to figure out what's going wrong, for example by looking through changelogs or using git bisect on git.git to find the change. It would have been much kinder to users to introduce a different symbol for “at the specified version, but dirty”.

You can fix it by:

  • either committing or undoing the changes/evolutions within each of your submodules, before going back to the parent repo (where the diff shouldn't report "dirty" files anymore). To undo all changes to your submodule just cd into the root directory of your submodule and do git checkout .

    dotnetCarpenter comments that you can do a: git submodule foreach --recursive git checkout .

  • or add --ignore-submodules to your git diff , to temporarily ignore those "dirty" submodules.

  • New in Git version 1.7.2

    As Noam comments below, this question mentions that, since git version 1.7.2, you can ignore the dirty submodules with:

    git status --ignore-submodules=dirty
    

    也删除子模块,然后运行git submodule initgit submodule update显然会做的伎俩,但可能并不总是适当或可能的。


    This is the case because the pointer you have for the submodule isn't what is actually in the submodule directory. To fix this, you must run git submodule update again:

    链接地址: http://www.djcxy.com/p/92374.html

    上一篇: 最新的git submodule跟踪

    下一篇: Git diff表示子项目很脏