如何清理.gitignore文件? [英] How do I clean up the .gitignore file?

查看:110
本文介绍了如何清理.gitignore文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在可用于删除.gitignore中不使用的行的git命令?

Is there git command that can be used to remove lines in .gitignore that are not used?

换句话说,我想删除对项目没有影响的模式.

In other words, I want to remove patterns that will not make a difference for the project.

推荐答案

Git并没有内置任何功能,因此您必须编写自己的代码,可能使用

There is nothing built in to Git to do this, so you would have to write your own code, probably using git check-ignore. Such a program would be quite complex since some ignore entries might be unused because of other existing ignore entries. As a somewhat silly example, if one entry says *.a, one says *.b, and a third says *.[ab], removing either or both of the first two is "safe" (makes no change in what gets ignored) as long as the third remains, but removing the third requires keeping both of the first two. This means that finding a truly minimal set of ignore entries would require trying all combinations.

无论如何,这通常不是一个好主意.例如,假设项目.gitignore包含这两行(以及其他两行):

In any case, it's not a good idea in general. Suppose, for instance, that the project .gitignore contains these two lines (among others):

*.dylib
*.dll

并且您正在使用Linux,但是构建共享的,动态加载的库的项目并不限于Linux.

and that you are working on Linux—but the project, which builds a shared, dynamically loaded library, is not limited to Linux.

这些行适用于Mac(第一行)和Windows(第二行)上的工作人员.您永远不会自己使用它们.您的系统既不构建DLL,也不构建Dylib文件.而是构建共享库(*.so)文件;而您构建的用于测试是否使用它们的任何自动代码都会说:不,不使用这些代码.因此,您可能会删除它们……并给 other 开发人员带来麻烦.如果他们运行了程序,它将删除使用的*.so行.

These lines are present for, and used by, those working on Macs (the first line) and Windows (the second one). You will never use them yourself. Your system builds neither DLLs nor Dylib files; it builds shared library (*.so) files instead; and any automatic code you build that tests whether you use them will say: no, these are not used. So you might remove them ... and cause trouble for other developers. If they ran your program, it would delete the *.so line that you are using.

(IDE也会发生这种情况,IDE可能会创建具有Git可以看到的隐藏"名称的文件或目录.如果您使用的鲍勃使用的IDE与Bob不同,而Carol使用的是第三种,则可能三个都需要不同的条目.可以使用您自己的全局排除"文件来解决此问题,如果您的编辑器制作了备份文件,这通常是正确的答案:如果Bob的编辑器制作了*~而Carol的制作了#*,则Bob可以在他的文件中放入*~个人全局排除项,而Carol可以将#*放在她的表中.同时,如果使用vim,则可以将.swp*.swp放在她的表中.但这有时也取决于项目.)

(This happens with IDEs as well, which may create files or directories with "hidden" names that Git can see. If you use a different IDE from Bob, and Carol uses a third, you may all three need different entries. It's possible to work around this using your own global "excludes" file, and that's usually the right answer if your editor makes backup files: if Bob's editor makes *~ while Carol's makes #*, Bob can put *~ in his personal global exclude, and Carol can put #* in hers. Meanwhile if you use vim, you would put .swp and *.swp in yours. But this also tends to be project-dependent sometimes.)

这篇关于如何清理.gitignore文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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