15

I've looked at this answer: Unignore subdirectories of ignored directories in Git

And as far as I can tell I am doing the same thing, but git refuses to unignore my directories/files.

These are my rules. I'm trying to just get the listed directories/subdirectories, but the entire public directory is not showing up.

/public/bootstrap/*
!/public/bootstrap/bower_components/bootstrap/dist/*
!/public/bootstrap/bower_components/bootstrap/dist/**/*
!/public/bootstrap/bower_components/bootstrap/less/variables.less

Any ideas?

Community
  • 1
  • 1
Joren
  • 9,623
  • 19
  • 63
  • 104
  • I just replicated this structure and `variables.less` was not ignored. Are you sure you don't have another `.gitignore` that might be catching it? – John Feminella Oct 22 '14 at 19:19
  • Did a find in the whole project folder, and the only other .gitignore is in a different directory and just has "local" in it. – Joren Oct 22 '14 at 19:22

3 Answers3

11

You can do it as follows. The sentence "You can't unignore more than one level deep per line" is not correct. You may refer to the answer here.

/public/bootstrap/**
!/public/bootstrap/**/
!/public/bootstrap/bower_components/bootstrap/dist/**
!/public/bootstrap/bower_components/bootstrap/less/variables.less
Community
  • 1
  • 1
Landys
  • 7,169
  • 3
  • 25
  • 34
  • So if I'm reading this right, the 1st line ignores all, the 2nd line unignores all directories, the 3rd line unignores all files and directories in dist? And, if I understand right, all the folders are now unignored, but since the files in the non-dist one are ignored, git won't do anything with them? – Joren Oct 24 '14 at 18:41
6

After doing some reading and a LOT of trial and error, this works:

/public/bootstrap/bower_components/jquery
/public/bootstrap/bower_components/bootstrap/**
!/public/bootstrap/bower_components/bootstrap/dist/
!/public/bootstrap/bower_components/bootstrap/dist/**
!/public/bootstrap/bower_components/bootstrap/less/
!/public/bootstrap/bower_components/bootstrap/less/variables.less

The issue seems to be this line in the docs: "It is not possible to re-include a file if a parent directory of that file is excluded."

This seems to directly contradict other answers, but appears to be how it works for me.

In my testing I found if you ignore like this:

/public/bootstrap/*

You can't unignore more than one level deep per line.

# doesn't work
!/public/bootstrap/bower_components/bootstrap/

# works
!/public/bootstrap/bower_components/
!/public/bootstrap/bower_components/bootstrap/
Joren
  • 9,623
  • 19
  • 63
  • 104
3

A command line that helps testing if you got it right: https://git-scm.com/docs/git-check-ignore

The following CLI:

git check-ignore -v .idea/bbb.txt .idea/workspace.xml .idea/runConfigurations/Android_Debug___ReactNative.xml android/.idea/aaaa.txt android/.idea/runConfigurations/app.xml

Outputs the following:

.gitignore:33:**/.idea/**   .idea/bbb.txt
.gitignore:33:**/.idea/**   .idea/workspace.xml
.gitignore:35:!**/.idea/runConfigurations/* .idea/runConfigurations/Android_Debug___ReactNative.xml
.gitignore:33:**/.idea/**   android/.idea/aaaa.txt
.gitignore:35:!**/.idea/runConfigurations/* android/.idea/runConfigurations/app.xml

Pay attention that the 3rd and 5th lines are successfully un-ignored (watch for the "!" sign).

My .gitignore file:

**/.idea/**
!**/.idea/runConfigurations/
!**/.idea/runConfigurations/*
A-S
  • 2,547
  • 2
  • 27
  • 37