git add -u

Here is a nice little tidbit I ran across some time ago…  Ever delete a bunch of files from a git working copy, and then had to go in and tell git that you meant to delete them?  For example:

[jason@dc40 AppStruct]$ git status
# On branch master
# Changed but not updated:
#   (use "git add/rm ..." to update what will be committed)
#
#       deleted:    Python/AppStruct/Application.py
#       modified:   Python/AppStruct/Database/PostgreSQL.py
#       deleted:    Python/AppStruct/Date.py
#       deleted:    Python/AppStruct/JSON.py
#       deleted:    Python/AppStruct/Util.py
#       deleted:    Python/AppStruct/__init__.py
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       Python/AppStruct/NewFile.txt
no changes added to commit (use "git add" and/or "git commit -a")

Previously, the way to handle this would be:

   git rm ...
   git rm ...
   git rm ...
   git rm ...
   git rm ...
   git add ...
   git add ...

Rather, isn’t this easier?

   git add -u
   git add .

From the man page for git-add:

–update | -u
Only match against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s