Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Won't Un-Ignore a Directory

Tags:

git

I'd like to only track certain directories in git in a larger project, where most directories will be excluded and only a few will be tracked. So, I wanted to use the not-operators in my .gitignore or excludes file, ja?

Why is this happening:

% mkdir wtfgit
% cd wtfgit 
% git init
Initialized empty Git repository in /home/foobar/wtfgit/.git/
% mkdir iwantthesefiles
% touch iwantthesefiles/foo
% mkdir idontwantthesefiles
% touch idontwantthesefiles/bar
% vim .gitignore
% cat .gitignore 
*
!iwantthesefiles/        
% git add --all
% git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

The "not" syntax works fine for files in the highest directory.

% touch baz          
% vim .gitignore
% cat .gitignore 
*
!iwantthesefiles/
!baz
% git add --all 
% git status    
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   baz
#

How can I get this to give me baz and foo as git tracked files? (Basically, how does the directory NOT-style globbing work at all?! It seems not to.)

Thanks!

like image 817
Clock Avatar asked Dec 29 '09 04:12

Clock


People also ask

Why is Git not ignoring files?

Git can only ignore files that are untracked - files that haven't been committed to the repository, yet. That's why, when you create a new repository, you should also create a . gitignore file with all the file patterns you want to ignore.


2 Answers

In case none of the above works try this variation inside .gitignore

Not working for me:
!build/**/*
Working for me:
!build**/*

For some reason this was the only way it worked for me.

like image 192
Tom Avatar answered Sep 21 '22 15:09

Tom


To forcefully add folders that are ignored, use:

git add -f my-ignored-folder
like image 31
TrinitronX Avatar answered Sep 21 '22 15:09

TrinitronX