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

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

问题描述

我最近重新组织了我的点文件,使其位于〜/ Dropbox / dotfiles 的Git存储库中,并且我正在使用病原体将所有Vim插件捆绑在〜/升降梭箱/点文件/家/的.vim /捆扎。这些插件被添加为Git子模块。现在问题是,当我运行Vim时,它会自动生成所有插件的文档,并将它们放入每个子模块目录中。这增加了未跟踪的内容到子模块,我想避免它。

  ruby​​-1.8.7-p330@gs〜 / Dropbox / dotfiles  $ git st 
#分支主
#已更改但未更新:
#(使用git add< file> ...更新内容将被提交)
#(使用git checkout - < file> ...放弃工作目录中的更改)
#(提交或放弃子模块中未跟踪或修改的内容)

#modified:home / .vim / bundle / fuzzyfinder(未跟踪内容)
#modified:home / .vim / bundle / l9(未跟踪内容)
#modified:home / .vim / bundle / matchit(未跟踪内容)
#modified:home / .vim / bundle / ruby​​(未跟踪内容)
#...
没有更改添加到提交中(使用git添加和/或git commit -a)

我试着添加一个 .gitignore 文件添加到我的Git存储库的根目录中,以忽略子模块内的所有 doc 文件夹,但这不会eem工作:

  home / .vim / bundle / ** / doc 

我的问题:是否有办法忽略Git子模块中的文件和文件夹,或者配置Vim来创建Git存储库之外的文件夹中的文档? / p>

编辑:正如Randy Morris指出的,这可能是通过病原体将标签生成到不同的位置

解决方案

您应该在每个子模块中添加 .gitignore

由于所述子模块类似于嵌套的Git回购,因此它们会照顾自己的忽略规则及其状态不会受到父回购的 .gitignore 影响(如>这里解释)。



对于特定于vim的设置,请参阅兰迪莫里斯在评论中提到,请参阅SO问题通过病原体生成标签到不同位置






注意:由于Nick 在此评论中提及,并且如

 

不同位置的病原体
> [submodulepath / to / submodule]
path = path / to / submodule
url = http://github.com/username/repo.git
ignore = untracked#< ====

可以工作并使该子模块被 git status

但是 ignore = untracked 表示至少 Git1.7.2






注意: nurettin 提及在评论中


ignore = dirty 为我完成

提交aee9c7d 详细介绍未跟踪




  • :只有超级项目中记录的提交和子模块 HEAD 将被视为修改,子模块工作树的所有更改都将被忽略

    使用此值时,子模块根本无法扫描工作树更改,从而在大型子模块上获得性能优势

  • 未跟踪 :只有子模块工作树中的未跟踪文件被忽略,更改 HEAD 和/或子模块中的修改文件将其标记为已修改。

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

解决方案

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.


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.

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

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