.gitignore 似乎没有生效

发布于 2024-10-11 07:35:46 字数 280 浏览 0 评论 0原文

我想让 git 忽略名为“Doxyfile”的文件,我添加了一个 .gitignore 文件,但它仍然尝试 来跟踪文件。

我在下面添加了我的步骤,我是否缺少一个步骤?

$ ls -a
  .git  .gitignore  README

$ cat .gitignore
  .DS_Store
  Doxyfile
  *~

$ touch Doxyfile

$ ls
  Doxyfile  README

$ git status -s
  ?? Doxyfile

I'd like for git to ignore the file named "Doxyfile", I added a .gitignore file but it still tries
to track the file.

I added my steps belowm am I missing a step?

$ ls -a
  .git  .gitignore  README

$ cat .gitignore
  .DS_Store
  Doxyfile
  *~

$ touch Doxyfile

$ ls
  Doxyfile  README

$ git status -s
  ?? Doxyfile

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

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

发布评论

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

评论(4

一抹苦笑 2024-10-18 07:35:46

如果您达到了 git 使用的高级水平,您了解它是如何工作的,并且您认为它应该忽略文件,但事实并非如此,您只需要以下三个命令:

git rm -r --cached .
git add . 
git commit -m '.gitignore synchronised'

这会执行从索引中删除所有内容的所有必要步骤添加所有内容又回来了。但是添加 git 时总是查找 .gitignore 文件,此时,其中提到的所有内容都不会添加到索引中。

.gitignore 现在可以满足您的期望

If you reached an advanced level of git usage, where you understand how it works and you think it should ignore files and it does not, you only need the following three commands:

git rm -r --cached .
git add . 
git commit -m '.gitignore synchronised'

This does all the necessary steps of removing everything from the index add everything back again. But when adding git always looks up the .gitignore file, at this point, everything mentioned in there will not be added to the index.

.gitignore now does what you expect

荒路情人 2024-10-18 07:35:46

我唯一能想到的是你的 .gitignore 中的“Doxyfile”行末尾有一个额外的空格,这会导致这种情况。

The only thing I could think of is that you have an extra space at the end of the "Doxyfile" line in your .gitignore, which would cause this.

会傲 2024-10-18 07:35:46

这可能是一个非常简单的错字。

确保 .gitignore 中的文件名前后都没有空格。添加空格会破坏预期的行为。

在这里,我遇到了类似的问题,因为我在配置变量中间错过了一个“s”:
为什么我的全局 .gitignore 文件不忽略?

检查并双击检查所有涉及的文件名。

It could be a very simple typo.

Make sure there is no spaces neither before nor after the file name in your .gitignore. Adding a space will break the intended behaviour.

Here, I got a similar problem because I missed an 's' in the middle of the configuration variable:
Why doesn't my global .gitignore file ignore?

check and double check all the file names involved.

昵称有卵用 2024-10-18 07:35:46

也许 Doxyfile 已经添加到存储库中,即使您运行 ls 时它不在本地?如果是这样,请先对其进行备份,然后 git rm Doxyfile 并确保它位于您的 .gitignore 中。提交此更改。然后将文件移回到存储库的文件夹中,这一次 git 应该会忽略它。

Perhaps Doxyfile has already been added to the repo, even though it's not present locally when you run ls? If so first make a backup of it, then git rm Doxyfile and make sure it's in your .gitignore. Commit this change. Then move the file back into your repo's folder and this time around it should be ignored by git.

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