Joren
Joren

Reputation: 9925

Git ignore unignore not working?

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?

Upvotes: 16

Views: 8636

Answers (3)

A-S
A-S

Reputation: 3145

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/*

Upvotes: 3

Landys
Landys

Reputation: 7757

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

Upvotes: 11

Joren
Joren

Reputation: 9925

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/

Upvotes: 8

Related Questions