git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: ls-files --exclude broken?

From
Jeff King <peff@peff.net>
Date
Sep 16, 2010, 00:50 UTC
Message-ID
<20100916005024.GA3428@sigill.intra.peff.net>
In-Reply-To
<AANLkTikd5uZFk8-d7wmB8ZEqOy5=RWsDNnrsHqAQZhkz@mail.gmail.com>
On Wed, Sep 15, 2010 at 08:33:29PM -0400, Jay Soffian wrote:
Show 11 quoted lines
> On Wed, Sep 15, 2010 at 8:16 PM, Jeff King <peff@peff.net> wrote:
> > It's not just the command line. It's also what's in .gitignore files. If
> > you disable just half of that, then you get the awful behavior that some
> > excludes apply to index files, and some don't.
> 
> Files matched by the standard excludes are not likely to be in the
> index in the first place. So in that sense, arguably -x is special.
> 
> But nonetheless, I agree with you, and since the user must
> specifically ask ls-files for the various exclusions, I think it makes
> sense to apply those even to cached files.

But then if somebody asks for both indexed and untracked files together, the behavior is quite confusing. There is no way to say "--exclude-standard just for the untracked files", and having exclusions impact cached files is unlike any other part of git. So the behavior of something like "git ls-files -s -o --exclude-standard" would be broken.

I have no idea if people are actually doing that.

So I think the best fix would be to leave the default behavior as-is, and add the --exclude-cached-files-too-pretty-please you mentioned.

Show 8 quoted lines
> I'm building a project file for my editor and I want to exclude
> certain files that make no sense for it to care about even though they
> are part of the repo. So I tried:
> 
> $ git ls-files -x png -x jpg ...
> 
> and was confused by that not working. I've worked around this by just
> filtering the ls-files output through grep, but, ick.

I certainly have sympathy for you being confused by the behavior of ls-files. It undoubtedly is a mess.

But as for having to use grep, I would feel worse for you if you were actually trying to exclude patterns from your .gitignore and you needed to _convert_ them into a grep pattern. But it doesn't seem like:

  git ls-files | grep -v '\.png$'
is really much more work, and it's way more flexible.

At one point I proposed a "git check-ignore" similar to "git check-attr", but I never got around to coding it. If you really liked the gitignore-style patterns for some reason, it would be a nice flexible way of doing what you want.

-Peff
Previous: Jay SoffianNext: Elijah Newren
Message 10 of 17 in “ls-files --exclude broken?”
  1. Jay SoffianSep 15, 2010
  2. Nguyen Thai Ngoc DuySep 15, 2010
  3. Junio C HamanoSep 15, 2010
  4. Jay SoffianSep 15, 2010
  5. Nguyen Thai Ngoc DuySep 15, 2010
  6. Jay SoffianSep 15, 2010
  7. Jay SoffianSep 15, 2010
  8. Jeff KingSep 16, 2010
  9. Jay SoffianSep 16, 2010
  10. Jeff KingSep 16, 2010
  11. Elijah NewrenSep 15, 2010
  12. Kevin BallardSep 15, 2010
  13. Daniel JohnsonSep 15, 2010
  14. git-ls-files.txt: clarify -x/--exclude optionJay Soffian, Sep 15, 2010
  15. Jeff KingSep 16, 2010
  16. Junio C HamanoSep 16, 2010
  17. Jeff KingSep 16, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.