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

Re: Make git ls-files omit deleted files

From
RRRaul Rangel <rrangel@google.com>
Date
Jan 16, 2024, 21:22 UTC
Message-ID
<CAHQZ30DmMYgTkKhWzK+H-TJN0dj2B-1Fhutu_=eRQd7vJCdjZQ@mail.gmail.com>
In-Reply-To
<xmqqply68c87.fsf@gitster.g>
On Fri, Jan 12, 2024 at 2:37 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 14 quoted lines
>
> Raul Rangel <rrangel@google.com> writes:
>
> > I'm trying to copy my current git worktree to a new directory, while
> > including all modified and untracked files, but excluding any ignored
> > files.
>
> Curiously missing from the above is "unmodified".  You only talked
> about modified, untracked, and ignored, but what do you want to do
> with them?
>
> As you are grabbing the files from the working tree, I suspect that
> you do not want to base your decision on what is in the index, which
> means that ls-files might be a wrong tool for the job.

Thanks for this insight. I ended up using `git ls-files` and `--ignored` to print out all the files that I want to ignore, and I converted that into a `find` exclusion list.

Here is the final command: $ git ls-files --others --ignored --exclude-standard --directory | (printf "%s\n" \( -path ./.git; sed -e 's/^/.\//' -e 's/\/$//' -e 's/^/-o\n-path\n/'; printf "%s\n" \) -prune -o ! -type d -print0 ) | xargs --exit find . | xargs -0 --max-procs 0 cp --parents --no-dereference -t /tmp/clone

This is actually a lot faster than I would have expected. Parallelizing the `cp` cuts the time down dramatically.

Thanks again!
p.s., Sorry for the resend. I forgot to send a plain text to the mailing list.
Previous: rsbecker@nexbridge.com
Message 5 of 5 in “Make git ls-files omit deleted files”
  1. Raul RangelJan 12, 2024
  2. Junio C HamanoJan 12, 2024
  3. Raul RangelJan 12, 2024
  4. rsbecker@nexbridge.comJan 12, 2024
  5. Raul RangelJan 16, 2024

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.