Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

  • Blog Navigation
The Multitalented 'git add' – rm-ing files and selectively staging changes

A problem I had as a git newbie, and one I’ve seen others struggle with, is the problem of how to conveniently stage the deletion of files which are already deleted from disk, but aren’t yet reflected in the index? That is, without ‘git rm’ing them one at a time or using some other hack (e.g. ‘git ls-files –deleted’) to do so.

The answer is ‘git add’

Specifically with the following options:

   -u, --update
       Update only files that git already knows about, staging modified content
       for commit and marking deleted files for removal.

   -A, --all
       Update files that git already knows about (same as --update) and add all
       untracked files that are not ignored by .gitignore mechanism.

Also of note: the very handy –patch options, which allows you to selective stage change changes on a change hunk or whole-file basis. –interactive is a more involved version of this. It’s a great way to untangle disparate changes for commit. More here.

   -p, --patch
       Add modified contents in the working tree interactively to the index.
Share This