Skip to contentSkip to conversation

git ignore

PATCH In review Max Power 5 participants 7 messages Jun 15, 2016

lore
Share & tools
lore

Max Power

author
#0 lore raw

So I understand how to use the .gitignore file to ignore specific files/directories that I put in there... is there a way to ignore everything BUT a given file extension?

Signature · 2 lines
View this message in context: http://www.nabble.com/git-ignore-tp21043430p21043430.html
Sent from the git mailing list archive at Nabble.com.
#1 lore raw
Quoted 4 lines · Max Power

So I understand how to use the .gitignore file to ignore specific files/directories that I put in there... is there a way to ignore everything BUT a given file extension?

Something like

	*
	!*.jpg

to only save the jpegs in your pr0n collection?

The first rule says "ignore everything". The second one says "don't ignore *.jpg files".

Untested.

Linus

#2 lore raw
Quoted 6 lines · Linus Torvalds
Quoted 4 lines · Max Power

So I understand how to use the .gitignore file to ignore specific files/directories that I put in there... is there a way to ignore everything BUT a given file extension?

Quoted 6 lines

Something like

	*
	!*.jpg

to only save the jpegs in your pr0n collection?

Hmm, do people still keep p0rn collection in jpgs? I somehow had an impression that they moved to avis ;-)

Quoted 4 lines

The first rule says "ignore everything". The second one says "don't ignore *.jpg files".

Untested.

t3001-ls-files-others-exclude.sh has some tests but there is nothing that explicitly tests overlapping patterns. Perhaps it should (hint, hint...)

"man gitignore" documentation has an example to ignore all *.html files but not foo.html using a similar construct, i.e.

	*.html
        !foo.html
#3 lore raw

PATCH 1/1 test overlapping ignore patterns

Add a test which checks that negated patterns such as "!foo.html" can override previous patterns such as "*.html". This is documented behaviour but had not been tested so far.

---
 t/t3001-ls-files-others-exclude.sh |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
t/t3001-ls-files-others-exclude.sh +6 -0
index 8666946..85aef12 100755
@@ -140,4 +140,10 @@ test_expect_success 'trailing slash in exclude forces directory match (2)' '
 
 '
 
+test_expect_success 'negated exclude matches can override previous ones' '
+
+	git ls-files --others --exclude="a.*" --exclude="!a.1" >output &&
+	grep "^a.1" output
+'
+
 test_done
Signature · 1 line
1.6.1.rc1
#4 lore raw

Re: [PATCH] test overlapping ignore patterns

Quoted 4 lines

Add a test which checks that negated patterns such as "!foo.html" can override previous patterns such as "*.html". This is documented behaviour but had not been tested so far.

Negated excludes with a pattern does not seem to work with sub directories, e.g. the following test fails for me.

The file /one/two/a.1 exists, and is initially excluded by *, but not re-included by "!*.1" (where as /a.1 is re-included).

(quoted diff) +0 -0

w/t/t3001-ls-files-others-exclude.sh
index c8fe978..e6c86ff 100755

t/t3001-ls-files-others-exclude.sh +0 -0
@@ -175,6 +175,12 @@ test_expect_success 'negated exclude matches can

override previous ones' '
grep "^a.1" output
'

+test_expect_success 'negated exclude matches can override previous ones 2' '
+
+ git ls-files --others --exclude="*" --exclude="!*.1" >output &&
+ grep "^one/two/a.1" output
+'
+

(Replying to this old thread via nabble; hopefully it works.)

- Stephen

--
View this message in context: http://git.661346.n2.nabble.com/git-ignore-tp1665336p6559395.html
Sent from the git mailing list archive at Nabble.com.

#5 lore raw

Re: [PATCH] test overlapping ignore patterns

Quoted 6 lines · Stephen Haberman

+test_expect_success 'negated exclude matches can override previous ones 2' '
+
+ git ls-files --others --exclude="*" --exclude="!*.1" >output &&
+ grep "^one/two/a.1" output
+'

Does this has anything to do with "negated overrides"?

Doesn't the first "*" tells us to not to look at the contents of one/ directory at all, so we that we do not have to waste time descending into it? We wouldn't even know what pathnames are underneath it, so "!*.1" would not have any effect inside one/ at all, I think.

#6 lore raw

Re: [PATCH] test overlapping ignore patterns

Quoted 5 lines

Doesn't the first "*" tells us to not to look at the contents of one/ directory at all, so we that we do not have to waste time descending into it? We wouldn't even know what pathnames are underneath it, so "!*.1" would not have any effect inside one/ at all, I think.

If that's the way the feature should work, that's fine.

I came across this thread via google referencing Linus's post from 2008 which mentioned versioning only jpg files. I want to do the same sort of thing, but with a directory hierarchy.

If I say "exclude *.jpg" in my root .gitignore file, that applies into sub directories, so I just assumed "exclude !*.jpg" would also apply to sub directories.

Am I missing another way to accomplish this?

I understand from an implementation perspective, skipping all subdirectories when you see "exlude *" is a smart thing to do, but perhaps it should only be done if there are no negative excludes that could bring items back into play?

Thanks,
Stephen