添加到 Git 子模块内的 .gitignore 文件

发布于 2024-10-19 21:05:37 字数 1293 浏览 3 评论 0 原文

我最近重新组织了我的点文件,使其位于 ~/Dropbox/dotfiles 的 Git 存储库中,并且使用 Pathogen 将所有 Vim 插件捆绑在 ~/Dropbox/dotfiles/home/.vim/ 中捆绑。这些插件作为 Git 子模块添加。

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

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 文件夹,但这似乎不起作用:

home/.vim/bundle/**/doc

我的问题:是有没有办法忽略 Git 子模块内的文件和文件夹,或者配置 Vim 在 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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不离久伴 2024-10-26 21:05:37

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

对于特定于 vim 的设置,如 Randy Morris 在评论中提到的,请参阅 SO 问题“根据病原体生成不同位置的标签”。


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

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

将起作用并生成该子模块被 git status 忽略。
但是“ignore = untracked表示至少 Git1.7.2

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


注意:nurettin 提到在评论中

ignore = dirty 为我做的

Commit aee9c7d 详细说明了未跟踪之间的区别。

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

  • untracked”:仅忽略子模块工作树中未跟踪的文件、子模块中已更改的 HEAD 和/或修改的文件会将其标记为已修改。

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.

叶落知秋 2024-10-26 21:05:37

VonC 的 ignore = untracked 建议可行,但您必须对每个此类子模块进行更改。

如果你想一劳永逸地解决问题,你可以在每个 git repo 上配置一个全局 gitignore 模式,通过 git config --global core.excludesfile ~/.gitignore_global ,然后只需添加 doc/tags 到 $HOME/.gitignore_global。

请参阅https://help.github.com/articles/ignoring-files

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.

南冥有猫 2024-10-26 21:05:37

本的回答是一个好的开始。但对于这种特定的忽略规则,我不喜欢全局设置。

首选每个子模块的本地配置,以及子模块根存储库中的集中忽略文件:

cd .vim/bundle
echo "doc/tags" > .gitignore_submodules
git submodule foreach git config --local core.excludesfile "../.gitignore_submodules"

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"
如果没有你 2024-10-26 21:05:37

我认为这里的基本问题是您试图忽略“跟踪”更改。 .gitignore 仅忽略对存储库的“未跟踪”更改。要验证您是否可以修改存储库(已跟踪)中的某些文件,并将其添加到您的 .gitignore 文件中。在执行 git status 时,您将看到该文件仍列为“已修改”。您的子模块存储库也被视为由主存储库跟踪,因此简单地向父存储库添加 gitignore 是行不通的。正如其他人所建议的,要么添加 .gitignore 规则单个存储库,或者如果您使用的是最新的 git 版本,则可以使用 git status --ignore-submodules 。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文