.gitignore files added inside Git submodules
Asked Answered
L

4

61

I recently reorganized my dotfiles to live inside a Git repository at ~/Dropbox/dotfiles and I'm using pathogen to bundle all Vim addons inside ~/Dropbox/dotfiles/home/.vim/bundle. These addons were added as Git submodules.

Now the problem is, when I run Vim, it automatically generates the documentation for all addons and puts them inside each submodule directory. This adds untracked content to the submodules, which I'd like to avoid.

ruby-1.8.7-p330@gs ~/Dropbox/dotfiles ‹master*› $ git st
# 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:   home/.vim/bundle/fuzzyfinder (untracked content)
#   modified:   home/.vim/bundle/l9 (untracked content)
#   modified:   home/.vim/bundle/matchit (untracked content)
#   modified:   home/.vim/bundle/ruby (untracked content)
#   ...
no changes added to commit (use "git add" and/or "git commit -a")

I tried to add a .gitignore file to the root of my Git repository to ignore all doc folders inside submodules, but this doesn't seem to work:

home/.vim/bundle/**/doc

My question: is there a way to ignore files and folders inside Git submodules or maybe configure Vim to create the documentation in a folder outside the Git repository?

EDIT: as Randy Morris pointed out, this might be a duplicate of Generating tags to different location by pathogen

Lucindalucine answered 26/2, 2011 at 13:30 Comment(4)
Possible duplicate: stackoverflow.com/questions/4343544/…Ornstead
You're right. Going to flag the question. Thanks!Lucindalucine
Note: ** in .gitignore does not mean “at any depth”.Lainelainey
Does this answer your question? Git: can I suppress listing of 'modified content'/dirty submodule entries in status, diff, etc?Gentlemanatarms
D
75

You should add .gitignore within each of your submodules.
Since said submodules are like nested Git repo, they take care of their own ignore rules, and their status wouldn't be influenced by the .gitignore of the parent repo (as explained here).

For a vim-specific setting, as Randy Morris mentions in the comment, see the SO question "Generating tags to different location by pathogen".


Note: as Nick mentions in this comments, and as illustrated by the answer to "Generating tags to different location by pathogen", a config like:

[submodule "path/to/submodule"]
    path = path/to/submodule
    url = http://github.com/username/repo.git
    ignore = untracked  # <====

will work and make that submodule ignored by git status.
But "ignore = untracked" means at least Git1.7.2.

The config is usually found in the .git/ folder of your repo.


Note: nurettin mentions in the comments:

ignore = dirty did it for me

Commit aee9c7d details the difference between untracked and dirty.

  • "dirty": Only differences of the commit recorded in the superproject and the submodules HEAD will be considered modifications, all changes to the work tree of the submodule will be ignored.
    When using this value, the submodule will not be scanned for work tree changes at all, leading to a performance benefit on large submodules.

  • "untracked": Only untracked files in the submodules work tree are ignored, a changed HEAD and/or modified files in the submodule will mark it as modified.

Debbydebee answered 26/2, 2011 at 13:36 Comment(4)
I don't like modifying other people's Git repositories, but the ignore = untracked option works just fine. Thank you very much!Lucindalucine
You need git version 1.7.2 at least for the ignore = untracked settings to work. See the comments here: stackoverflow.com/questions/4343544/…Marrowfat
ignore = dirty did it for meMccomb
@Mccomb interesting. I have included the dirty value option in the answer for more visibility.Debbydebee
S
8

VonC's recommendation of ignore = untracked works, but you have to make the change for every such submodule.

If you want to solve the problem once and for all, you can configure a global gitignore pattern on every git repo, by git config --global core.excludesfile ~/.gitignore_global, then just add doc/tags to $HOME/.gitignore_global.

See https://help.github.com/articles/ignoring-files.

Substratum answered 19/2, 2012 at 23:19 Comment(0)
S
2

Ben's answer is a good start. But for such specific ignore rule, I don't like the global setting.

Prefer local config for each submodule, and a centralized ignore file in submodule root repository:

cd .vim/bundle
echo "doc/tags" > .gitignore_submodules
git submodule foreach git config --local core.excludesfile "../.gitignore_submodules"
Shelly answered 18/6, 2014 at 9:22 Comment(0)
M
-2

I think the basic problem here is that you are trying to ignore a 'tracked' change. .gitignore ignores only 'untracked' changes to the repo. To verify you can modify some file in your repo (which tracked) and also add it to your .gitignore file. On doing git status you will see that the file is still listed as 'modified'. Your submodule repo's are also considered tracked by your main repo, hence simply adding a gitignore to the parent repo won't work. As othere suggested, either add .gitignore rules individual repo's or if you're using a recent git version, you can use the git status --ignore-submodules.

Magisterial answered 4/5, 2011 at 9:21 Comment(1)
nope. those files are new and they are 'untracked'. sorry, but that doesn't help solving the problem.Lucindalucine

© 2022 - 2024 — McMap. All rights reserved.