奇怪的.gitignore行为为emacs临时文件 [英] Strange .gitignore behavior for emacs temporary files

查看:236
本文介绍了奇怪的.gitignore行为为emacs临时文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我用emacs编辑 new_file.txt ,会有临时文件,例如#new_file.txt#。#new_file.txt 当文件未保存时, new_file.txt〜保存时。
我想排除这些文件。所以我写了 .gitignore 像这样:

 #这是一个评论栏
*〜
[#] * [#]
。\#*

这完美地工作。但后来我给它添加了一些注释行:

 #这是注释行
*〜
[#] * [#]#这是一条评论
。\#*#这是另一条评论

git status 之后,我看到#new_file.txt#。#new_file.txt 被列为未跟踪文件。

我认为 .gitignore 可能会在字符作为注释行的开始。所以我删除了这两条评论。然而,在另一个 git status 之后,我仍然可以看到#new_file.txt#。# new_file.txt 列为未跟踪文件。



我这样做:

  git rm -r --cached。 

。gitignore not working,但它没有帮助。

有人可以告诉我发生了什么事情,以及如何使 .gitignore 按我的意愿工作?非常感谢你! 任何跟踪文件模式的注释都会被解释为该模式的一部分。



将您的注释移动到模式之前的行,并且它应该返回到它的初始行为。 p>

If I edit new_file.txt with emacs, there will be temporary files like #new_file.txt# and .#new_file.txt when the files are unsaved, and new_file.txt~ when saved. I want to exclude these files. So I write my .gitignore like this:

#This is a comment line
*~
[#]*[#]
.\#*

And this works perfectly. But later I add some comment lines to it:

#This is a comment line
*~
[#]*[#]     # this is a comment
.\#*     # this is another comment

After a git status, I see both #new_file.txt# and .#new_file.txt are listed as the untracked files.

I think .gitignore may get confused at the # character as the beginning of the comment line. So I remove those two comment lines. However, after another git status, I still see #new_file.txt# and .#new_file.txt listed as the untracked files.

I do :

git rm -r --cached .

as suggested in ".gitignore not working", but it doesn't help.

Could someone please tell me what happened, and how to make .gitignore work as I wish? Thank you very much!

解决方案

Comments on .gitignore files must be on their own line - any comment trailing a file pattern is interpreted as part of that pattern.

Move your comments to the line before the pattern, and it should return to its initial behavior.

这篇关于奇怪的.gitignore行为为emacs临时文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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