如何阻止 .gitignore 出现在未跟踪文件列表中? [英] How can I stop .gitignore from appearing in the list of untracked files?

查看:25
本文介绍了如何阻止 .gitignore 出现在未跟踪文件列表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在我的新项目的根目录上做了一个 git init.

I just did a git init on the root of my new project.

然后我创建了一个 .gitignore 文件.

Then I created a .gitignore file.

现在,当我输入 git status 时,.gitignore 文件出现在未跟踪文件列表中.这是为什么?

Now, when I type git status, .gitignore file appears in the list of untracked files. Why is that?

推荐答案

.gitignore 文件应该在你的仓库中,所以它确实应该被添加和提交,如 git status 建议.它必须是存储库树的一部分,以便可以合并对其的更改等.

The .gitignore file should be in your repository, so it should indeed be added and committed in, as git status suggests. It has to be a part of the repository tree, so that changes to it can be merged and so on.

所以,把它添加到你的仓库中,它不应该被 gitignored.

So, add it to your repository, it should not be gitignored.

如果您确实需要,可以将 .gitignore 添加到 .gitignore 文件中,如果您不想提交它.但是,在这种情况下,最好将忽略添加到 .git/info/exclude,这是一个特殊的 checkout-local 文件,其工作方式与 .gitignore 类似,但不会出现在git status"中,因为它位于 .git 文件夹中.

If you really want you can add .gitignore to the .gitignore file if you don't want it to be committed. However, in that case it's probably better to add the ignores to .git/info/exclude, a special checkout-local file that works just like .gitignore but does not show up in "git status" since it's in the .git folder.

另见https://help.github.com/articles/ignoring-files

这篇关于如何阻止 .gitignore 出现在未跟踪文件列表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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