简体   繁体   English

.gitignore-忽略文件目录

[英].gitignore - directory of ignore files

Is there any way to create a .gitignore folder rather than a file? 有什么方法可以创建.gitignore文件夹而不是文件? Such that Git would parse .gitignore/ignorerulesA and .gitignore/ignorerulesB both as ignore files? 这样Git会将.gitignore / ignorerulesA和.gitignore / ignorerulesB都解析为忽略文件?

I could see this being useful in a scenario where I have two repositories with a non-overlapping structure that I want to merge. 我可以看到这在我有两个要合并的非重叠结构存储库的情况下很有用。

repoa
  filea
  foldera
  .gitignore/ignorea

repob
  fileb
  folderb
  .gitignore/ignoreb

With this structure I can merge repoa and repob without any conflicts. 通过这种结构,我可以合并repoa和repob而不会发生任何冲突。

If this isn't possible already, would it make sense to request this feature? 如果这还不可能,请求此功能是否有意义?

I'm not sure if the search results for my question are so poor because: 我不确定我的问题的搜索结果是否如此差,因为:

  1. maybe this is just a bad idea 也许这只是一个坏主意
  2. I don't have the right search term ".gitignore folder" is just a bunch of instructions on how to ignore a folder. 我没有正确的搜索词“ .gitignore文件夹”,只是关于如何忽略文件夹的一堆指令。 "multiple .gitignore files" just talks about placing .gitignores in different folders. “多个.gitignore文件”只是谈论将.gitignores放置在不同的文件夹中。
  3. I'm a genus and nobody has thought of this before. 我是一个属,以前没有人想到过。

Update: Clarification 更新:澄清

If we take the two repositories in my example above and apply different .gitignore rules for each repository. 如果我们在上面的示例中采用了两个存储库,并对每个存储库应用不同的.gitignore规则。

For instance in repoa I want to ignore foldera and in repob I want to ignore fileb. 例如,在repoa中,我想忽略foldera,而在repob中,我想忽略fileb。 I end up in this situation 我最终遇到这种情况

repoa
  filea
  foldera
  .gitignore
    foldera

repob
  fileb
  folderb
  .gitignore
    fileb

Now I want to create repoab. 现在我要创建仓库。

mkdir repoab
cd repoab
git init
git remote add repoa /path/to/repoa
git remote add repob /path/to/repob
git pull repoa master
git pull repob master
rom ../repob
 * branch            master     -> FETCH_HEAD
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.

Essentially every single time I deal with an update to repoa or repob I'm going to have to deal with this conflict, which is certainly not ideal. 基本上,每次我处理repoa或repob的更新时,我都必须处理这种冲突,这当然不是理想的。

You can ignore directories with <directoryname>/ . 您可以使用<directoryname>/忽略目录。

In your example adding file*/ will ignore both folders, and there won't be a merge conflict if you try to merge the 2 repo/branch. 在您的示例中,添加file*/将忽略两个文件夹,并且如果您尝试合并2个仓库/分支,则不会发生合并冲突。

As you found searching for "multiple .gitignore files", you can put different files in different directories, but Git doesn't handle multiple .gitignore files in one directory. 当您搜索“多个.gitignore文件”时,可以将不同的文件放在不同的目录中,但是Git不在一个目录中处理多个.gitignore文件。 In general, Git looks for a configuration file like this in your pwd and then crawls up to parent directories until it finds one or reaches the root directory. 通常,Git在您的pwd寻找这样的配置文件,然后爬到父目录,直到找到一个或到达根目录为止。 That strategy doesn't mesh with having a special directory full of multiple configuration files. 该策略与拥有包含多个配置文件的特殊目录没有关系。

Though this won't solve your merging problem (I think you need submodules for that), you can set up a global .gitignore for things like editor swapfiles that other collaborators don't need to ignore. 尽管这不能解决您的合并问题(我认为您需要子模块 ),但是您可以为其他协作者不需要忽略的诸如编辑器交换文件之类的内容设置全局.gitignore I have one at ~/.gitignore and tell Git to read it in ~/.gitconfig : 我在~/.gitignore有一个,告诉Git在~/.gitconfig阅读它:

[core]
  excludesfile = /Users/kristjan/.gitignore

With this structure I can merge repoa and repob without any conflicts. 通过这种结构,我可以合并repoa和repob而不会发生任何冲突。

But you can't. 但是你不能。 .gitignore files can have exclusions, and even without those it's possible for one repo to expect some kinds of files to be included where the other expects them to be generated (and so ignores them). .gitignore文件可以具有排除项,即使没有这些排除项,一个回购也可能会期望包含某些类型的文件,而另一个则希望它们会生成(因此忽略它们)。 Order matters. 顺序很重要。

You can put your .gitignore s in the trees they apply to, foldera/.gitignore and so forth. 您可以将.gitignore放入应用于它们的树中, foldera/.gitignore等等。 That won't help for toplevel files, but if you've got conflicting specs there you also have conflicting files there, so the ignore mess isn't really the problem there. 这对顶级文件没有帮助,但是如果那里的规范冲突,那么那里的文件也会冲突,因此,忽略混乱并不是真正的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM