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

Re: git-ls-files(1) avoiding symlinks

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 6, 2026, 20:16 UTC
Message-ID
<xmqqeccxhg0f.fsf@gitster.g>
In-Reply-To
<au4rmQRjRtIv1Oru@debian>
Alejandro Colomar <alx+git@kernel.org> writes:
Show 7 quoted lines
>> > With -z it becomes a bit tedious:
>> > 
>> >    $ git ls-files -z --format='%(objectmode) %(path)' \
>> >    | grep -zv ^120000 \
>> >    | sed -z 's/^.* //' \
>> >    | grep -z '\.[ch]$' \
>> >    | xargs -0 grepc creat;
Shouldn't the grep|sed|grep be doable with a single sed invocation?
Show 5 quoted lines
>> > I expect git-ls-files(1) could make this much simpler, though:
>> > 
>> >    $ git ls-files --type f \
>> >    | grep '\.[ch]$' \
>> >    | xargs grepc creat;

Not really. Why is "--type" have to be so special? What would the next person ask for? --size?

The "ls-files" plumbing command is designed as a component to build your own pipeline with. Don't throw in random unrelated features to it. In the longer run, it is not a good substitute for improving the skill to construct a good pipeline.

Learn the tools available to you that you already have heard of, so that you can make better uses of them (in this case "sed"). If you squash the grep|sed|grep pipeline into a single sed

    git ls-files -z -s "*.[ch]" |
    sed -z -n -e '/^120000/d' -e '/^.* 0	/s///p' |
    xargs -r -0 ls -ld
the result does not look too bad.

One unrelated tip for better readability is to end, not begin, your lines with the "|" pipe characters. That way you do not have to sprinkle so many unsightly backslashes ;-).

HTH.
Previous: Alejandro ColomarNext: Alejandro Colomar
Message 5 of 6 in “git-ls-files(1) avoiding symlinks”
  1. Alejandro ColomarNov 6, 2026
  2. D. Ben KnobleNov 6, 2026
  3. Alejandro ColomarNov 6, 2026
  4. Alejandro ColomarNov 6, 2026
  5. Junio C HamanoNov 6, 2026
  6. Alejandro ColomarNov 6, 2026

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.