您应该将 .gitignore 提交到 Git 存储库中吗?

发布于 2024-11-03 04:35:04 字数 98 浏览 4 评论 0原文

您认为将 .gitignore 提交到 Git 存储库是一个好习惯吗?

有些人不喜欢它,但我认为它很好,因为你可以跟踪文件的历史记录。不是吗?

Do you think it is a good practice to commit .gitignore into a Git repo?

Some people don't like it, but I think it is good as you can track the file's history. Isn't it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

牵你的手,一向走下去 2024-11-10 04:35:04

通常是的,.gitignore 对于每个想要使用存储库的人来说都是有用的。有时您会想忽略更多私人的事情(也许您经常创建LOG或其他东西。在这些情况下,您可能不想将其强加给其他人。

Normally yes, .gitignore is useful for everyone who wants to work with the repository. On occasion you'll want to ignore more private things (maybe you often create LOG or something. In those cases you probably don't want to force that on anyone else.

北方的韩爷 2024-11-10 04:35:04

您通常提交.gitignore。事实上,当我不做某事时,我个人会尽可能确保我的索引始终是干净的。 (git status 应该不显示任何内容。)

在某些情况下,您想要忽略实际上不特定于项目的内容。例如,您的文本编辑器可能会创建自动 *~ 备份文件,或者另一个示例是 OS X 创建的 .DS_Store 文件。

我想说,如果其他文件是抱怨这些规则弄乱了您的 .gitignore,请将它们排除在外,并将它们放入全局排除文件中。

默认情况下,此文件位于 $XDG_CONFIG_HOME/git/ignore 中(默认为 ~/.config/git/ignore),但可以通过设置 来更改此位置>core.excludesfile 选项。例如:

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

只需创建并编辑全局排除文件即可;它将适用于您在该机器上使用的每个 git 存储库。

You typically do commit .gitignore. In fact, I personally go as far as making sure my index is always clean when I'm not working on something. (git status should show nothing.)

There are cases where you want to ignore stuff that really isn't project specific. For example, your text editor may create automatic *~ backup files, or another example would be the .DS_Store files created by OS X.

I'd say, if others are complaining about those rules cluttering up your .gitignore, leave them out and instead put them in a global excludes file.

By default this file resides in $XDG_CONFIG_HOME/git/ignore (defaults to ~/.config/git/ignore), but this location can be changed by setting the core.excludesfile option. For example:

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

Simply create and edit the global excludesfile to your heart's content; it'll apply to every git repository you work on on that machine.

坚持沉默 2024-11-10 04:35:04

我放置了 commit .gitignore,这是对其他可能构建我的项目的人的礼貌,以下文件是派生的,应该被忽略。

我通常做混合动力。我喜欢让 makefile 生成 .gitignore 文件,因为 makefile 将知道与项目派生或其他方式关联的所有文件。然后签入一个顶级项目 .gitignore,它将忽略由 makefile 为各个子目录创建的生成的 .gitignore 文件。

因此,在我的项目中,我可能有一个 bin 子目录,其中包含所有构建的可执行文件。然后,我将让我的 makefile 为该 bin 目录生成 .gitignore。在顶级目录 .gitignore 中列出了 bin/.gitignore。最上面的一张是我签到的。

I put commit .gitignore, which is a courtesy to other who may build my project that the following files are derived and should be ignored.

I usually do a hybrid. I like to make makefile generate the .gitignore file since the makefile will know all the files associated with the project -derived or otherwise. Then have a top level project .gitignore that you check in, which would ignore the generated .gitignore files created by the makefile for the various sub directories.

So in my project, I might have a bin sub directory with all the built executables. Then, I'll have my makefile generate a .gitignore for that bin directory. And in the top directory .gitignore that lists bin/.gitignore. The top one is the one I check in.

想你的星星会说话 2024-11-10 04:35:04

提交 .gitignore 可能非常有用,但您要确保此后不会对其进行过多修改,尤其是在您定期在分支之间切换时。
如果这样做,您可能会遇到文件在一个分支中被忽略而不是在另一个分支中的情况,迫使您手动删除或重命名工作目录中的文件,因为签出失败,因为它会覆盖非跟踪文件。

因此,是的,请务必提交您的 .gitignore,但前提是您有理由确定此后它不会发生太大变化。

Committing .gitignore can be very useful but you want to make sure you don't modify it too much thereafter especially if you regularly switch between branches.
If you do you might get cases where files are ignored in a branch and not in the other, forcing you to go manually delete or rename files in your work directory because a checkout failed as it would overwrite a non-tracked file.

Therefore yes, do commit your .gitignore, but not before you are reasonably sure it won't change that much thereafter.

芸娘子的小脾气 2024-11-10 04:35:04

对我来说,我认为将 .gitignore 文件提交到存储库是个好主意。当有人克隆您的存储库并构建项目,或者运行一些确实生成一些垃圾数据的测试时,可能不需要推送它。.gitignore 文件只是忽略其中配置的文件。

For me I think it is a good idea to commit .gitignore file to the repository. When someone clones your repository and build project, or run some tests that does generate some junk data may not needed to push it.. .gitignore file just ignore files that are configured in it..

送你一个梦 2024-11-10 04:35:04

.gitignore 至少您的构建产品(程序、*.o 等)是一个很好的做法。

It is a good practice to .gitignore at least your build products (programs, *.o, etc.).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文