When would you use .git/info/exclude instead of .g

2019-01-16 07:07发布

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

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 gitignore
4条回答
劳资没心,怎么记你
2楼-- · 2019-01-16 07:25

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.

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.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-16 07:26

Googled : 3 ways of excluding files

  • .gitignore is applied to every clone of the repo (it comes along as a versioned file),
  • .git/info/exclude only applies to your local copy of the repository.
  • ~/.gitconfig only applies to your computer globally
查看更多
男人必须洒脱
4楼-- · 2019-01-16 07:38

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.

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.

.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.

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

查看更多
来,给爷笑一个
5楼-- · 2019-01-16 07:46

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.

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.

Does that help?

查看更多
登录 后发表回答