Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: inverse ignoring (.gitignore)

Tags:

I created a repository for my home folder. This is my .gitignore file:

!.vim/plugin/* !.vim/doc/* .* * .viminfo .vim/.netrwhist .vim-fuf-data/file/stats bin/dwm/dwm 

So when I create a new file inside .vim/plugin I expected that after git status this file was shown, but no..why?

EDIT: after a pair of answers I changed the position of inverse ignoring lines this way below, but the problems is the same: the new files I create inside the .vim/plugin folder are not shown after git status..

.* * .viminfo .vim/.netrwhist .vim-fuf-data/file/stats bin/dwm/dwm !.vim/plugin/* !.vim/doc/* 
like image 592
ziiweb Avatar asked Nov 15 '12 13:11

ziiweb


People also ask

How do I ignore a .gitignore file?

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.

Why is git ignoring my Gitignore?

Some times, even if you haven't added some files to the repository, git seems to monitor them even after you add them to the . gitignore file. This is a caching issue that can occur and to fix it, you need to clear your cache.

Can you ignore a Gitignore?

gitignore , nor in the global . gitignore , can be ignored using explicit repository excludes in your_project_directory/. git/info/exclude . This file will not be shared with other developers, and is specific for that single repository.


2 Answers

In line 4 you're ignoring everything with *. This overrides the previous negating pattern. From the man page:

within one level of precedence, the last matching pattern decides the outcome

Where "level of precedence" means different sources for ignore patterns like .gitignore and $GIT_DIR/info/exclude.

If you want to ignore everything but the patterns beginning with ! you should move the * to the beginning of .gitignore


Edit

I found a solution with the help of another question on SO:

* !*/ !.vim/plugin/* 
like image 117
Deve Avatar answered Sep 18 '22 21:09

Deve


Try moving the negated lines (those starting with !) to the bottom of the .gitignore file.

See the Examples section here

like image 41
garyh Avatar answered Sep 18 '22 21:09

garyh