Git diff says subproject is dirty

后端 未结 9 1755
情话喂你
情话喂你 2020-11-28 17:47

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/bufe         


        
相关标签:
9条回答
  • 2020-11-28 17:55
    git submodule foreach --recursive git checkout .
    

    This didn't do the trick for me but it gave me a list of files (in my case only one) that had been changed in the submodule (without me doing anything there).

    So I could head over to the submodule and git status showed me that my HEAD was detached -> git checkout master, git status to see the modified file once again, git checkout >filename<, git pull and everything fine again.

    0 讨论(0)
  • 2020-11-28 18:03

    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:

    0 讨论(0)
  • 2020-11-28 18:04

    In my case I wasn't sure what had caused this to happen, but I knew I just wanted the submodules to be reset to their latest remote commit and be done with it. This involved combining answers from a couple of different questions on here:

    git submodule update --recursive --remote --init

    Sources:

    How do I revert my changes to a git submodule?

    Easy way to pull latest of all git submodules

    0 讨论(0)
  • 2020-11-28 18:09

    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
    
    0 讨论(0)
  • 2020-11-28 18:11

    A submodule may be marked as dirty if filemode settings is enabled and you changed file permissions in submodule subtree.

    To disable filemode in a submodule, you can edit /.git/modules/path/to/your/submodule/config and add

    [core]
      filemode = false
    

    If you want to ignore all dirty states, you can either set ignore = dirty property in /.gitmodules file, but I think it's better to only disable filemode.

    0 讨论(0)
  • 2020-11-28 18:13

    I ended up removing the submodule directory and initializing it once again

    cd my-submodule
    git push
    cd ../
    rm -rf my-submodule
    git submodule init
    git submodule update
    
    0 讨论(0)
提交回复
热议问题