git submodules with modified and untracked content – why and how to remove it?

this is what my git status‘ result looks like:

# On branch master
# Changed but not updated:
#   (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:   vim/bundle/pathogen (modified content)
#   modified:   vim/bundle/sparkup (untracked content)
#
no changes added to commit (use "git add" and/or "git commit -a")

running git diff vim shows this:

  • Git - rm --cached .idea and fatal pathspec
  • How to clean up line-endings with Git
  • What is the right way to maintain a “version for the server” - with only config files changed, in Git?
  • git .gitignore not ignore all my files
  • IntelliJ Idea: Disable Auto Commit on Merge
  • code share between web app and cordova app
  • diff --git a/vim/bundle/pathogen b/vim/bundle/pathogen
    --- a/vim/bundle/pathogen
    +++ b/vim/bundle/pathogen
    @@ -1 +1 @@
    -Subproject commit fcf77f5101f3e589ce006c40ad3a0432735a05cf
    +Subproject commit fcf77f5101f3e589ce006c40ad3a0432735a05cf-dirty
    diff --git a/vim/bundle/sparkup b/vim/bundle/sparkup
    --- a/vim/bundle/sparkup
    +++ b/vim/bundle/sparkup
    @@ -1 +1 @@
    -Subproject commit 04a81b41f116a19184359a6f8685c192f5c36c70
    +Subproject commit 04a81b41f116a19184359a6f8685c192f5c36c70-dirty
    

    Why is the one untracked, the other modified, what does the diff mean? But most important: how did it happen and how to get rid of it?

  • updating description of project in bare repository
  • Can I version control my .bash_profile?
  • Automatically Fetch Branch, Run Script, and Push to Other Branch
  • Create a new BitBucket repository for existing files from Ubuntu
  • Number of commits on branch in git
  • How to git commit in a new branch after I've already made the changes?
  • 6 Solutions collect form web for “git submodules with modified and untracked content – why and how to remove it?”

    One of the tracked files in vim/bundle/pathogen has been modified somehow. There is also some untracked (and unignored) content in the submodule vim/bundle/sparkup. In either case, the way to figure out what is modified / untracked is to change into the submodule directory and run git status. (In the case of untracked files in a submodule, this is frequently a build product that has not been added to .gitignore in upstream.)

    Add ignore = dirty to each problematic submodule section in .gitmodules files placed at root of repo. Example:

    [submodule "vim/bundle/nerdtree"]                                               
      path = vim/bundle/nerdtree                                                    
      url = https://github.com/scrooloose/nerdtree.git                              
      ignore = dirty
    

    As seen at NilsH’s How to ignore changes in git submodules. Found thanks to Synchronizing plugins with git submodules and pathogen vimcast.

    Head into the submodule’s directory and make sure there isn’t anything being built (an output of some kind) w/o you knowing.

    cd submoduledir/
    git status
    

    If you see any untracked files in here, just do this to remove them:

    git reset --hard HEAD
    git clean -fxd
    

    If you’re really sure you want to just do it (I’m managing vim bundles with pathogen and git submodules and some how I managed to get some tags folders in repos – and they just had to go) you can loop through submodules and remove untracked files.

    cd YOUR_REPO_WITH_SUBMODULES/
    git submodule foreach git clean -f -d
    

    -f to force, -d to remove directories

    You can check the docs here: https://git-scm.com/docs/git-clean

    As the author of pathogen states in the FAQ, you can ignore tags globally:

    git config --global core.excludesfile '~/.cvsignore'
    echo tags >> ~/.cvsignore
    

    You can clean your repository with:

    git clean -fd
    
    -f is force and git won't do anything without the flat
    -d is for also removing directories
    

    If the directory is managed by a different repository you use the f flag twice to remove it

    git clean -ffd
    

    Documentation: git clean

    Git Baby is a git and github fan, let's start git clone.