Friday, February 19, 2010

Git gotchas: batch deletes and single reverts.

Git is great and most of the time easy to use but there are some scenarios that I'm finding counter-intuitive.

Staging a group of deletes

if you have a load of files in a repository you want to delete (with some you don't wish to). It can seem a pain in the backside to delete them individually with the
git rm
Fileglobs may not be suitable and the '. -r' flags may delete more than you want.

The easiest way to deal with this is to delete the files from your local copy and call:
git add -update
git add -u
This flag does the following:
Update only files that git already knows about, staging modified content for commit and marking deleted files for removal. This is similar to what "git commit -a" does in preparation for making a commit, except that the update is limited to paths specified on the command line. If no paths are specified, all tracked files in the current directory and its subdirectories are updated.

Reverting or resetting an individual file

If you come from the SVN world to restore a file to its original state you would revert it. git revert does not do that. Perhaps you want to reset it? git reset does not do that either.
The command you need to use is
git checkout --filename
This checks out the original file from the repository again.

So remember to delete you add and to revert you checkout.
Intuitive my arse...

No comments: