为什么.gitignore不起作用?

thi*_*365 5 git version-control gitignore

我的问题不同于为什么gitignore在这种情况下没有工作?也没有.gitignore不工作

files/conf.php已经在.gitignore中,但git status仍显示其修改,为什么?

我的意思是如果它在.gitignore中不应该跟踪这个文件...

cat .gitignore
files/conf.php
[root@home blogmi]# git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   files/conf.php
#
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)

Lil*_*ard 11

.gitignore只忽略未跟踪的文件.一旦开始跟踪文件(就像你已经完成的那样files/conf.php),它就不会被忽略.

您可以使用git rm --cached files/conf.php从git中删除文件而不实际从文件系统中删除它.提交后,文件将开始被正确忽略.

  • @iight:它没有上传提交.该文件实际上已由repo提交和跟踪,但包含未分级的更改.这并不重要.在第二个问题中,`git add`实际上会忽略该文件(我相信它会告诉你它跳过了文件).你必须使用`git add -f $ file`才能使它工作. (2认同)