← back to all talks and articles

Removing deleted files from the Git staging area

When working with Git it can be cumbersome to have to remove files from the index (marking them deleted rahter missing) if you did not delete them using git-rm. Here’s bash one-liner for that:

git rm $(git ls-files -d)

What that does is use ls-files -d to list all files in the project that are deleted from the file system, and apply the rm command to those paths to delete them from the git index.

I’ve got that aliased to grd (Git Remove Deleted).

  • code
  • git
Arjan van der Gaag

Arjan van der Gaag

A thirtysomething software developer, historian and all-round geek. This is his blog about Ruby, Rails, Javascript, Git, CSS, software and the web. Back to all talks and articles?

Discuss

You cannot leave comments on my site, but you can always tweet questions or comments at me: @avdgaag.