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

Make git ls-files omit deleted files

From
RRRaul Rangel <rrangel@google.com>
Date
Jan 12, 2024, 21:19 UTC
Message-ID
<CAHQZ30Ad6+YM9qnCOeNNy8e2k-AbYR_bBXTups-7z6=ioyqS5Q@mail.gmail.com>

Hello, 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. I essentially want a copy of the tree assuming someone ran `git add --all && git commit` and cloned that commit into a different directory.

I got pretty close with the following command:
    $ git ls-files --cached --modified --others --exclude-standard
--deduplicate | xargs cp --parents --no-dereference
--target-directory=/tmp/clone/

The problem is that if I have an unstaged delete, `ls-files` will print it out as a modification and `cp` will print an error saying that it failed to copy the non-existing file.

The man page states this behavior:
> --modified: Show files with an unstaged modification (note that an unstaged deletion also counts as an unstaged modification)

Is there another way to achieve what I'm doing that's not too expensive? If not, could a `--no-deleted-as-modified` flag be added?

Thanks, Raul

Next: Junio C Hamano
Message 1 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.