Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git ignore is not ignoring the netbeans private files

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.

like image 355
Sheik797 Avatar asked May 27 '15 07:05

Sheik797


People also ask

Why git ignore is not ignoring files?

gitignore only ignores files that are not part of the repository yet. If you already git add ed some files, their changes will still be tracked. To remove those files from your repository (but not from your file system) use git rm --cached on them.

How do I set git to ignore files?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.


1 Answers

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.

like image 135
CodeWizard Avatar answered Oct 12 '22 12:10

CodeWizard