Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference between a/ and a/* and a/** in .gitignore?

Tags:

git

gitignore

Here is my file folder.

a
├─ b
│  ├─ b1.txt
│  └─ b2.txt
├─ a1.txt
└─ a2.txt
.gitignore

Firstly:

I found if I wanna ignore the folder a, a/ and a/* and a/** all can complete.

Secondly:

I wanna ignore all the things in folder a except the folder b, the only way to do this is:

a/*
!a/b/

I don't know why a/** can't do this?

# this way can't except folder b
a/**
!a/b/

Or you can tell me how can I use a/** ?

like image 230
tomision Avatar asked May 24 '17 11:05

tomision


People also ask

What does asterisk mean in Gitignore?

An asterisk " * " matches anything except a slash. The character " ? " matches any one character except " / ". The range notation, e.g. [a-zA-Z] , can be used to match one of the characters in a range.

Can Gitignore have comments?

We can also put comments in the gitignore file by just putting a # sign in front of any text that we want to be a comment in the gitignore file, maybe we want to provide the reason why we ignored something and any blank lines are simply going to be skipped.

Does Gitignore ignore subdirectories?

gitignore resides. If the pattern starts with a slash, it matches files and directories only in the repository root. If the pattern doesn't start with a slash, it matches files and directories in any directory or subdirectory.

What is a trailing asterisk?

A trailing asterisk (*) indicates that a DISPLAY command applies to all jobs or started tasks that match a leading character string. The DISPLAY JOBS, J, A, or TS command supports only a trailing asterisk.


1 Answers

** matches any amount of directories, * only one.
So if you e. g. ignore /a/**/d/, then /a/b/d/ and /a/b/c/d/ both are ignored.
If you e. g. ignore /a/*/d/, then /a/b/d/ is ignored while /a/b/c/d/ is not ignored.

If a folder is ignored, then Git does not even look at its contents to check for inclusions. That is why you cannot ignore /a/ and then include /a/b/, as Git does not even look into /a/. Because of this you must instead ignore all contents in /a/ with /a/* and then include /a/b/ to ignore everything in /a/, except all contents of /a/b/.

like image 148
Vampire Avatar answered Oct 20 '22 05:10

Vampire