奇怪的.gitignore行为为emacs临时文件 [英] Strange .gitignore behavior for emacs temporary files
问题描述
如果我用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,但它没有帮助。
有人可以告诉我发生了什么事情,以及如何使
将您的注释移动到模式之前的行,并且它应该返回到它的初始行为。 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屋!