How do I list everything except markdown files? I have tried to run ls-files with the --exclude flag, but the excluded files are still shown in the output.
My git version is 2.6.4 (Apple Git-63)
$ git ls-files ChromeExt/read-coffee Node/README.md Node/web-scraping README.md $ git ls-files --exclude *.md ChromeExt/read-coffee Node/README.md Node/web-scraping README.md
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
)
That was already discussed in 2010:
There is no indication in the man page that -x doesn't apply to -c.
Hence the addition:
Since b5227d8,
-x/--exclude
does not apply to cached files.
This is easy to miss unless you read the discussion in theEXCLUDE PATTERNS
section. Clarify that the option applies to untracked files and direct the reader toEXCLUDE PATTERNS
.
The git ls-files
man page does mentions:
-x <pattern> --exclude=<pattern>
Skip untracked files matching pattern
If your Readme.md
is tracked, the exclude pattern won't apply.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With