你什么时候会使用 .git/info/exclude 而不是 .gitignore 来排除文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22906851/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:58:13  来源:igfitidea点击:

When would you use .git/info/exclude instead of .gitignore to exclude files?

gitgitignore

提问by Parag

I am a bit confused about the pros and cons of using .git/info/excludeand .gitignoreto exclude files.

我对使用.git/info/exclude.gitignore排除文件的利弊有点困惑。

Both of them are at the level of the repository/project, so how do they differ and when should we use .git/info/exclude?

它们都处于存储库/项目级别,那么它们有何不同以及我们应该何时使用.git/info/exclude

回答by u1860929

The advantage of .gitignoreis that it can be checked into the repository itself, unlike .git/info/exclude. Another advantage is that you can have multiple .gitignorefiles, one inside each directory/subdirectory for directory specific ignore rules, unlike .git/info/exclude.

的好处.gitignore是,它可以检查到库本身,不像.git/info/exclude。另一个优点是您可以有多个.gitignore文件,每个目录/子目录中有一个文件,用于目录特定的忽略规则,与.git/info/exclude.

So, .gitignoreis available across all clones of the repository. Therefore, in large teams all people are ignoring the same kind of files Example *.db, *.log. And you can have more specific ignore rules because of multiple .gitignore.

因此,.gitignore可用于存储库的所有克隆。因此,在大型团队中,所有人都会忽略相同类型的文件 Example *.db, *.log. 由于多个.gitignore.

.git/info/excludeis available for individual clones only, hence what one person ignores in his clone is not available in some other person's clone. For example, if someone uses Eclipsefor development it may make sense for that developer to add .buildfolder to .git/info/excludebecause other devs may not be using Eclipse.

.git/info/exclude仅适用于单个克隆,因此一个人在其克隆中忽略的内容在其他人的克隆中不可用。例如,如果有人Eclipse用于开发,那么该开发人员添加.build文件夹可能是有意义的,.git/info/exclude因为其他开发人员可能没有使用 Eclipse。

In general, files/ignore rules that have to be universally ignored should go in .gitignore, and otherwise files that you want to ignore only on your local clone should go into .git/info/exclude

一般来说,必须普遍忽略的文件/忽略规则应该进入.gitignore,否则你只想在本地克隆上忽略的文件应该进入.git/info/exclude

回答by LeGEC

Googled : 3 ways of excluding files

谷歌搜索:排除文件的 3 种方法

  1. .gitignoreapplies to every clone of this repository (versioned, everyone will have it),
  2. .git/info/excludeonly applies to your local copy of this repository (local, not shared with others),
  3. ~/.gitignoreapplies to all the repositories on your computer (local, not shared with others).
  1. .gitignore适用于此存储库的每个克隆(版本化,每个人都会拥有它),
  2. .git/info/exclude仅适用于您的此存储库的本地副本(本地,不与他人共享),
  3. ~/.gitignore适用于您计算机上的所有存储库(本地,不与他人共享)。

3.actually requires to set a configuration on your computer :

3.实际上需要在您的计算机上设置配置:

git config --global core.excludesfile '~/.gitignore'

回答by Effing

Just to offer our (real world) experience: we started using .git/info/exclude when we had to customize some config files on each development environment but still wanted the source to be maintained in the repo and available to other developers.

只是为了提供我们的(真实世界)经验:当我们不得不在每个开发环境中自定义一些配置文件但仍希望源代码在 repo 中维护并可供其他开发人员使用时,我们开始使用 .git/info/exclude。

This way, the local files, once cloned and modified can be excluded from commits without affecting the original files in the repo but without necessarily being ignored in the repo either.

这样,本地文件,一旦被克隆和修改,就可以从提交中排除,而不会影响存储库中的原始文件,但也不必在存储库中被忽略。

回答by Marnen Laibow-Koser

Use .gitignorefor ignore rules that are specific to the project. Use excludeor a global ignore file for ignore rules that are specific to your environment.

使用.gitignore的忽略了特定的规则项目。使用exclude或 全局忽略文件来忽略特定于您的环境的规则。

For example, my global ignore files ignore the temp files generated by whatever editor I'm using—that rule is specific to my environment, and might be different for some other developer on the same project (perhaps they use a different editor). OTOH, my project .gitignorefiles ignore things like API keys and build artifacts—those are for the project, and should be the same for everyone on the project.

例如,我的全局忽略文件忽略由我使用的任何编辑器生成的临时文件——该规则特定于我的环境,对于同一项目的其他开发人员可能会有所不同(也许他们使用不同的编辑器)。OTOH,我的项目.gitignore文件忽略了 API 密钥和构建工件之类的东西——这些是针对项目的,对于项目中的每个人都应该是相同的。

Does that help?

这有帮助吗?