Is rm equivalent for "add."?

If you use Git from the command line, is there a way to delete in one fell swoop all the files that will be deleted in the Modified but not updated list? Instead of manually deleting with wildcards.

+7
git git-add git-rm
source share
3 answers

Files shown as deleted in the โ€œModified but Not Updatedโ€ section of the state are deleted from the work tree, but not from the index. To perform a deletion in an index (i.e. remove a file from an index), you can do:

git diff -z --name-only --diff-filter=D | git update-index --remove -z --stdin 

--diff-filter=D only shows the differences from the index, which is the deleted file, --name-only just prints its name, and -z uses NUL to separate file names, so you do not have to worry about file names with embedded characters new line. update-index then removes the data from the index.

If you have a version of xargs that supports -0 , you can make it a little easier:

 git diff -z --name-only --diff-filter=D | xargs -0 git rm 
+3
source share

The following should contain all files, deleted or missing, in the index:

 git add -A 
+8
source share

Well, the files listed in the Modified section but not updated are already in the index. You can discard your changes using git checkout .
To delete a file that is new but not added to the index, you can use git clean .
But to delete files that were changed in the index ... well, there is no easy solution, you probably have to use a combination of git rm and git ls-files .

EDIT:
git ls-files -m should indicate the files you are looking for. Combine it with git rm and you will do:

 git-ls files -m | xargs git rm // NOT TESTED 

EDIT:
I probably misunderstood part of your question. My solution will delete all the files listed in the Modified section, but not updated. If you want to delete files listed as deleted, you should use git diff , as Charles Bailey shows in his answer.

+4
source share

All Articles