我为什么要使用gitignore? [英] Why should I use gitignore?

查看:152
本文介绍了我为什么要使用gitignore?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,无论何时我创建一个我希望Git跟踪的文件,只需将其添加到索引即可。如果我不把它添加到索引Git不会看到它。那么为什么我应该使用gitignore文件,而不是将它添加到索引?

你一般会发现在你的项目变得更大时,逐个添加每个文件可能会变得乏味。



在Java中,最终可能会有许多 .class 您不想添加到存储库的文件。同样,你最终可能会在C中有很多 .o 文件,或者Python中的 .pyc (例如)。
$ b 具有 *。class *。o *。pyc 在您的 .gitignore 文件中,您可以一劳永逸地忽略这些文件。后续 git status 运行(或类似如果您使用GUI)不会告诉您这些是新的未跟踪文件,从而让您专注于真正新的文件并且显然未被跟踪。



如果您添加整个目录(例如 git add myproject ),这也会很有用:这可以让你完全忽略一类文件。


Currently, whenever I create a file that I'd like Git to track I simply add it to the index. If I don't add it to the index Git would not "see it". So why should I use a gitignore file, as opposed to just not adding it to the index?

解决方案

You'll generally find that adding each and every file one by one can become tedious when your project becomes bigger.

In Java, you may end up with many .class files that you wouldn't want to add to your repository. Similarly, you may end up with many .o files in C, or .pyc in Python (for example).

Having patterns like *.class, *.o, *.pyc in your .gitignore files allows you to ignore those files once and for all. Subsequent git status runs (or similar if you're using a GUI) will not tell you these are new, untracked files, thereby letting you focus on the files that are really new and noticeably untracked.

This can also be useful if you add an entire directory (e.g. git add myproject): this lets you ignore a category of files altogether.

这篇关于我为什么要使用gitignore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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