Is there a way to remove from an index with a single command only those files that have been added with -N flag?
No. Git doesn't keep track of which files were added with -N
and which were simply empty.
Yes, there is! Using only git:
git diff --name-only --diff-filter=A -z \
| git restore --staged -q --pathspec-file-nul --pathspec-from-file=-
Files that are added without their content with -N
show up as 'Added' (A
) in the work tree, and that is what is listed with --diff-filter=A
. This list is then piped into git restore
which removes the intent-to-add.
I used git restore
because git reset
just resets the whole index if there are no files added with -N
(because the pathspec is empty). You can also avoid this problem with
git diff --name-only --diff-filter=A -z | xargs -r0 git reset -q --
which requires GNU xargs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With