添加到 Git 子模块中的 .gitignore 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5127178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.gitignore files added inside Git submodules
提问by rubiii
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.
我最近重新组织了我的 dotfiles 以位于 Git 存储库中,~/Dropbox/dotfiles
并且我正在使用病原体将所有 Vim 插件捆绑在~/Dropbox/dotfiles/home/.vim/bundle
. 这些插件是作为 Git 子模块添加的。
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.
现在的问题是,当我运行 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")
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:
我试图将一个.gitignore
文件添加到我的 Git 存储库的根目录以忽略doc
子模块内的所有文件夹,但这似乎不起作用:
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?
我的问题:有没有办法忽略 Git 子模块内的文件和文件夹,或者配置 Vim 以在 Git 存储库外的文件夹中创建文档?
EDIT: as Randy Morris pointed out, this might be a duplicate of Generating tags to different location by pathogen
编辑:正如 Randy Morris 所指出的,这可能是Generating tags to different location by pathogen的重复
回答by VonC
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).
您应该.gitignore
在每个子模块中添加。
由于所述子模块就像嵌套的 Git 存储库,它们会处理自己的忽略规则,并且它们的状态不会受到.gitignore
父存储库的影响(如此处所述)。
For a vim-specific setting, as Randy Morrismentions in the comment, see the SO question "Generating tags to different location by pathogen".
对于特定于 vim 的设置,正如Randy Morris在评论中提到的,请参阅 SO 问题“通过病原体将标签生成到不同位置”。
Note: as Nickmentions 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.
将工作并使该子模块被git status
.
但是 " ignore = untracked
"至少意味着Git1.7.2。
Note: nurettinmentions in the comments:
ignore = dirty
did it for me
ignore = dirty
为我做的
Commit aee9c7ddetails the difference between untracked
and dirty
.
提交aee9c7d细节之间的差异untracked
和dirty
。
"
dirty
": Only differences of the commit recorded in the superproject and the submodulesHEAD
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 changedHEAD
and/or modified files in the submodule will mark it as modified.
"
dirty
": 只有在超级项目和子模块中记录的提交的差异HEAD
才会被认为是修改,对子模块的工作树的所有更改都将被忽略。
使用此值时,根本不会扫描子模块的工作树更改,从而提高大型子模块的性能。"
untracked
": 仅忽略子模块工作树中未跟踪的文件,子模块中更改HEAD
和/或修改的文件会将其标记为已修改。
回答by Ben Challenor
VonC's recommendation of ignore = untracked
works, but you have to make the change for every such submodule.
VonC 的ignore = untracked
作品推荐,但您必须对每个此类子模块进行更改。
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.
如果你想一劳永逸地解决问题,你可以在每个 git repo 上配置一个全局的 gitignore 模式,by git config --global core.excludesfile ~/.gitignore_global
,然后只需添加doc/tags
到 $HOME/.gitignore_global 即可。
回答by Jér?me
Ben's answer is a good start. But for such specific ignore rule, I don't like the global setting.
Ben 的回答是一个好的开始。但是对于这种特定的忽略规则,我不喜欢全局设置。
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"
回答by Mandeep Sandhu
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
.
我认为这里的基本问题是您试图忽略“跟踪”更改。.gitignore
仅忽略对 repo 的“未跟踪”更改。要验证您可以修改您的存储库中的某些文件(已跟踪)并将其添加到您的.gitignore
文件中。完成后,git status
您将看到该文件仍列为“已修改”。您的子模块存储库也被认为是由主存储库跟踪的,因此简单地向父存储库添加 gitignore 是行不通的。正如其他人所建议的,要么添加.gitignore
单独的 repo 规则,要么如果您使用的是最新的 git 版本,则可以使用git status --ignore-submodules
.