Git ignore不会忽略netbeans私有文件

She*_*797 8 git netbeans gitignore

当我做git状态时,netbeans private.xml会出现问题,我尝试在git中添加几个方法.但是gitignore根本不会忽视它.

git status
On branch master
Your branch is up-to-date with 'origin/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:   .gitignore
   modified:   nbproject/private/private.xml
...
Run Code Online (Sandbox Code Playgroud)

我的git忽略文件是

node_modules/
dist/
*.log
nbproject/private/*    
*.bak
*.orig
*~
*.log
*private.xml
Run Code Online (Sandbox Code Playgroud)

在同一个文件中尝试了nbproject/private/*和*private.xml.

Von*_*onC 18

已经跟踪的文件不会被忽略:您需要先从索引中删除.

git rm --cached private.xml 
git add -u .
git commit -m "Record deletion of private.xml from the index"
Run Code Online (Sandbox Code Playgroud)

(该--cached选项确保文件保留在磁盘上)

然后你可以在.gitignore中添加它(不需要'*')

private.xml 
Run Code Online (Sandbox Code Playgroud)

注意:无论何时忽略文件,您都可以查看.gitignore适用的规则:

git check-ignore -v -- private.xml
Run Code Online (Sandbox Code Playgroud)


Cod*_*ard 5

您的文件已添加到 git 存储库中。
添加文件(不是未跟踪)后,将其添加到 .gitignore 将不会忽略它,因为它已经在存储库中,因此您必须将其从存储库中删除,提交删除文件,然后它将被忽略。

请参阅上面的VonC代码了解如何执行此操作。

需要理解的重要一点是,一旦文件已经提交,将其添加到 gitignore 将不会忽略它。