Git ignore is not ignoring the netbeans private files

萝らか妹 提交于 2019-11-27 16:36:20

问题


When ever I do git status, the netbeans private.xml is making trouble, I tried adding that in git ignore several ways. but the gitignore simply does not ignore it.

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
...

My git ignore file is

node_modules/
dist/
*.log
nbproject/private/*    
*.bak
*.orig
*~
*.log
*private.xml

Tried both nbproject/private/* and *private.xml in the same file.


回答1:


A file which is already tracked would not be ignored: you need to remove from the index first.

git rm --cached private.xml 
git add -u .
git commit -m "Record deletion of private.xml from the index"

(the --cached option make sure the file remains on the disk)

Then you can add it in the .gitignore (no need for '*')

private.xml 

Note: whenever an file is or is not ignored, you can check out which .gitignore rule applies with:

git check-ignore -v -- private.xml



回答2:


Your file is already added to the git repo.
Once file is added (not untracked) adding it to .gitignore will not ignore it since its already in the repo so you have to remove it from the repository, commit the deletion of the file and then it will be ignored.

See VonC code above on how to do it.

The important thing to understand is that once the file is already commited, adding it to git ignore will not ignore it.



来源:https://stackoverflow.com/questions/30475920/git-ignore-is-not-ignoring-the-netbeans-private-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!