(Don't have the reputation to comment on the previous reply, but this is in reply to it)
Yes, there is! Using only git:
git diff --name-only --diff-filter=A -z | git restore --staged -q --pathspec-file-nul --pathspec-from-file=-
This is really great, but git add -AN
also stages file deletions, and this command doesn't unstage those file deletions. We can fully reverse the git add -AN
command with this command:
cat <(git diff --name-only --diff-filter=A -z) <(git diff --staged --name-only --diff-filter=D -z) | git restore --staged -q --pathspec-file-nul --pathspec-from-file=-
We need to run two different commands and cat them, because we can only see the deleted files when using git diff --staged
.