Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all deleted files from "changed but not updated" in Git

Tags:

When I run git status, I have a bunch of lines of the form

deleted:    dir/file.js 

I can remove each of these individually with git checkout -- dir/file.js, but there must be a less painstaking way to do so. (And yes, I know I should've used git rm in the first place...)

[Update: As Mark points out below, git checkout -- actually restores a deleted file, whereas I'd thought that it deleted it from the git index. I was a little baffled, because when you run git status, it says:

use "git checkout -- <file>..." to discard changes in working directory 

To me, "discard changes" doesn't mean "restore a file you deleted," but in git terminology I suppose this makes sense.]

like image 480
Trevor Burnham Avatar asked Jul 03 '10 00:07

Trevor Burnham


People also ask

How do I remove a deleted file from my git repository?

Delete Files using git rm. The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.

Does git diff show deleted files?

You can use git diff --name-status, that will show you files that where added, modified and deleted.

Does git reset restore deleted files?

Git keeps a log of all the changes made to files within a repository. You can restore a file that you have deleted since a previous commit by using the git checkout command. This command lets you navigate to a previous point in your repository's history.


1 Answers

As rampion points out, you can still use git rm to stage the deletion of files that have already been deleted in your working copy (e.g. just git rm dir/file.js in your case.) If you have a lot of these files listed as "deleted:" under "Changed but not updated", I would first check that git ls-files --deleted produces a list of these files, and, if so, delete them with:

git ls-files --deleted -z | xargs -0 git rm 
like image 129
Mark Longair Avatar answered Sep 20 '22 19:09

Mark Longair