Git似乎忽略了我的.gitignore文件-.gitignorefile是否已损坏?Git希望使用哪种文件格式、区域设置或文化?

我的.gitignore:

# This is a comment
debug.log
nbproject/

git状态的输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.log和nbproject/不出现在未跟踪的文件列表中。

我应该从哪里开始解决这个问题?


当前回答

此问题的另一个原因是语句前的空格或制表符:

例子:

# Be aware of the following:
 notWorkingIgnore.*
workingIgnore.*

正如下面的评论所指出的,尾随空格也是一个问题:

# Be aware of the following:
notWorkingIgnore.* #<-Space
workingIgnore.*#<-Nospace

其他回答

我的问题是我写下了要忽略的文件,用引号“”分隔,而不是用斜线/分隔。

这不起作用,被git忽略了:

"db.sqlite3"
"tdd_venv/"

这很好:

/db.sqlite3
/tdd_venv/

我还用Notepad++检查了windows中的文件编码。编码设置为UTF-8。

只需通过以下命令删除之前在Git中提交的文件夹或文件。然后gitignore文件将反映正确的文件。

    git rm -r -f "folder or files insides"

gitignore还有一个问题可能会发生,特别是对于Windows用户。Git不喜欢你命名.gitignore(例如unity.gitignore)。

您希望始终将其命名为.gitignore,或者在Windows上命名为.git ignore,因为Windows认为您正在尝试重命名它而不使用文件名。

还可以查看放置.gitignore的目录。

它应该位于项目的根目录中:

./myproject/.gitignore

不在

./myproject/.git/.gitignore

我的没有工作,因为我确实创建了一个名为.gitignore的文本文档

相反,创建一个文本文档,在Notepad++中打开它,然后另存为.gitignore

保存时,确保从下拉列表中选择所有类型(*.*)。


或者在gitbash中,只需使用touch.gitignore