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

February 13, 2009 Pivotal Labs

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.

About the Author

Biography

Previous
Split testing with Rails Part 2 – The Results Are In
Split testing with Rails Part 2 – The Results Are In

In my last article I ask you to visit Blabs and participate in a simple split test. A few hundred of you w...

Next
Split testing with Rails
Split testing with Rails

At Pivotal we are all about rapid iteration and continual feedback for our code, and try to get our clients...