Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange .gitignore behavior for emacs temporary files

Tags:

git

emacs

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!

like image 858
shva Avatar asked Jul 16 '12 04:07

shva


1 Answers

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.

like image 53
David Cain Avatar answered Sep 26 '22 12:09

David Cain