How do I exclude files from git ls-files?

Git has its own way to extend glob patterns, and that includes a way to exclude files that match one pattern but not another. For example, the following will list all paths not ending in .md:

git ls-files -- . ':!:*.md'

It’s important to quote the pattern, because you want git to parse it, not the shell.

And to match all files ending with .js, except the ones ending with .min.js:

git ls-files -- '*.js' ':!:*.min.js'

You can also use this with other commands, such as git grep:

git grep -w funcname -- '*.js' ':!:*.min.js'

This syntax is explained under pathspec in gitglossary (or git help glossary or man gitglossary)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)