添加到 Git 子模块中的 .gitignore 文件 [英] .gitignore files added inside Git submodules

查看:46
本文介绍了添加到 Git 子模块中的 .gitignore 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近重新组织了我的 dotfiles 以位于 ~/Dropbox/dotfiles 的 Git 存储库中,并且我正在使用病原体将所有 Vim 插件捆绑在 ~/Dropbox/dotfiles/home/.vim/bundle.这些插件是作为 Git 子模块添加的.

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.

现在的问题是,当我运行 Vim 时,它会自动为所有插件生成文档并将它们放在每个子模块目录中.这会向子模块添加未跟踪的内容,我想避免这种情况.

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")

我尝试将 .gitignore 文件添加到我的 Git 存储库的根目录以忽略子模块内的所有 doc 文件夹,但这似乎不起作用:

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

我的问题:有没有办法忽略 Git 子模块内的文件和文件夹,或者可以配置 Vim 在 Git 存储库外的文件夹中创建文档?

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?

正如 Randy Morris 所指出的,这可能是 按病原体生成不同位置的标签

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

推荐答案

您应该在每个子模块中添加 .gitignore.
由于所述子模块就像嵌套的 Git 存储库,它们会处理自己的忽略规则,并且它们的状态不会受到父存储库的 .gitignore 的影响(如 在这里解释).

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).

对于特定于 vim 的设置,正如 Randy Morris 在评论中提到的,请参阅 SO 问题按病原体生成不同位置的标签".

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

注意:正如 Nick 在此评论中提到的,以及对按病原体生成不同位置的标签",配置如下:

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  # <====

将工作并使该子模块被 git status 忽略.
但是ignore = untracked"意味着至少Git1.7.2.

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

该配置通常位于您的存储库的 .git/ 文件夹中.

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

注意:nurettin 提到了 在评论中:

ignore =dirty 为我做的

提交 aee9c7d 详细说明了 untracked.

  • "dirty":只有超级项目和子模块HEAD中记录的commit的差异才会被认为是修改,对子模块工作树的所有更改都将被忽略.
    使用此值时,根本不会扫描子模块的工作树更改,从而提高大型子模块的性能.

  • "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":仅忽略子模块工作树中未跟踪的文件、更改的 HEAD 和/或修改的文件在子模块中将其标记为已修改.

"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.

这篇关于添加到 Git 子模块中的 .gitignore 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆