你什么时候会使用 .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
When would you use .git/info/exclude instead of .gitignore to exclude files?
提问by Parag
I am a bit confused about the pros and cons of using .git/info/exclude
and .gitignore
to 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 .gitignore
is that it can be checked into the repository itself, unlike .git/info/exclude
. Another advantage is that you can have multiple .gitignore
files, one inside each directory/subdirectory for directory specific ignore rules, unlike .git/info/exclude
.
的好处.gitignore
是,它可以检查到库本身,不像.git/info/exclude
。另一个优点是您可以有多个.gitignore
文件,每个目录/子目录中有一个文件,用于目录特定的忽略规则,与.git/info/exclude
.
So, .gitignore
is 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/exclude
is 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 Eclipse
for development it may make sense for that developer to add .build
folder to .git/info/exclude
because 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 种方法
.gitignore
applies to every clone of this repository (versioned, everyone will have it),.git/info/exclude
only applies to your local copy of this repository (local, not shared with others),~/.gitignore
applies to all the repositories on your computer (local, not shared with others).
.gitignore
适用于此存储库的每个克隆(版本化,每个人都会拥有它),.git/info/exclude
仅适用于您的此存储库的本地副本(本地,不与他人共享),~/.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 .gitignore
for ignore rules that are specific to the project. Use exclude
or 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 .gitignore
files 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?
这有帮助吗?