How to add and commit removals made with “rm” instead of “git rm”?

0 votes
asked Dec 6, 2009 by kch

I deleted a bunch of files and directories from a Git repository using rm, the Finder, etc.

I'm looking for a Git command that'll record these to the index as marked for removal, as if I had called git rm on them.

I understand git add -u will do this, along with a bunch of other things. I'd like my command to exclusively handle removals.

4 Answers

0 votes
answered Dec 6, 2009 by kch

Charles Bailey's answer nudged me towards this, but I still welcome something shorter.

$ git diff --name-only --diff-filter=D | xargs git rm
0 votes
answered Dec 6, 2009 by greg-bacon

Without spaces in filenames:

$ git rm `git ls-files -d`

More robust:

$ git ls-files -z -d | xargs -0 --no-run-if-empty git rm
0 votes
answered Dec 14, 2014 by stephen-quan

In Git 2.0, git add behaves like git add --ignore-removal <pathspec> which ignores paths you removed from your working tree.

You can use git add --all <pathspec> to record the removals.

Run git status to check the paths you removed from your working tree.

0 votes
answered Dec 26, 2014 by roman

This command will give you a list of all deleted files which will be forward to git rm. So all files will be removed. If no deleted files were found, nothing will be happen:

git ls-files -z -d | xargs -0 --no-run-if-empty git rm

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...