threads / discuss / 48631

git glob pattern in .gitignore and git command

Subject: git glob pattern in .gitignore and git command

## tl;dr

3 messages between Jun 3, 2018 and Jun 3, 2018.

replies: 2people: 3as markdown or json

Yubin Ruan· Jun 3, 2018, 00:58 UTC · lore

To ignore all .js file under a directory `lib', I can use "lib/**/js" to match them. But when using git command such as "git add", using "git add lib/\*.js" is sufficient. Why is this difference in glob mode?

I have heard that there are many different glob mode out there (e.g., bash has many different glob mode). So, which classes of glob mode does these two belong to? Do they have a name?

Yubin
Philip Oakley· Jun 3, 2018, 17:34 UTC · re: Yubin Ruan · lore

Re: git glob pattern in .gitignore and git command

Hi Yubun,
From: "Yubin Ruan" <ablacktshirt@gmail.com>
Show 11 quoted lines
> To ignore all .js file under a directory `lib', I can use "lib/**/js" to
> match
> them. But when using git command such as "git add", using "git add
> lib/\*.js"
> is sufficient. Why is this difference in glob mode?
>
> I have heard that there are many different glob mode out there (e.g., bash
> has
> many different glob mode). So, which classes of glob mode does these two
> belong to? Do they have a name?
>

Is this a question about `git add` being able to add a file that is marked as being ignored in the .gitignore file? [Yes it can.]

Or, is this simply about the many different globbing capabilities of one's shell, and of Git?

The double asterix (star) is specific/local to Git. It is described in the various commands that use it, especially the gitignore man page `git help ignore` or https://git-scm.com/docs/gitignore. "Two consecutive asterisks ("**") in patterns matched against full pathname may have special meaning: ... "

The single asterix does have two modes depending on how you quote it. It is described in the command line interface (cli) man page ` git help cli` or https://git-scm.com/docs/gitcli. "Many commands allow wildcards in paths, but you need to protect them from getting globbed by the shell. These two mean different things: ... "

A common proper name for these asterix style characters is a "wildcards". Try 'bash wildcards' or linux wildcards' in your favourite search engine.

-- Philip

Duy Nguyen· Jun 3, 2018, 17:43 UTC · re: Yubin Ruan · lore

Re: git glob pattern in .gitignore and git command

On Sun, Jun 3, 2018 at 2:58 AM, Yubin Ruan <ablacktshirt@gmail.com> wrote:
> To ignore all .js file under a directory `lib', I can use "lib/**/js" to match
> them. But when using git command such as "git add", using "git add lib/\*.js"
> is sufficient. Why is this difference in glob mode?

Historical reasons mostly. '**' comes later when '*' already establishes its place. You can use '**' too with "git add ':(glob)lib/**/*.js'". See https://git-scm.com/docs/gitglossary#gitglossary-aiddefpathspecapathspec

-- 
Duy

← back to recent threads