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/不出现在未跟踪的文件列表中。

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


当前回答

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

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

其他回答

如果您是Notepad++用户,请尝试执行以下操作:

使用Notepad++打开.gitignore文件,然后执行以下操作:

菜单编辑→ EOL转换→ Windows格式→ 拯救

再次尝试使用gitstatus,看看它是否适合您。

我在这里发布了类似问题的答案。

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

例子:

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

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

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

每当我遇到git正在跟踪.gitignore中列出的文件的情况时,我会使用以下方法:

git update-index --skip-worktree <file_name>

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

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

"db.sqlite3"
"tdd_venv/"

这很好:

/db.sqlite3
/tdd_venv/

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

我注意到.gitignore的编码产生了影响——如果文件是Unicode,它会被忽略,如果是ASCII,它不会被忽略。

流程:

验证状态:PS>git状态创建一个函数以获取文件编码Test.gitignore的编码:PS>Get-FileEncoding.gitignor将编码更改为ASCII:PS>Set-Content.gitignore-encoding ASCII-Value(Get-Content.gitignore)确认:PS>git状态