tags:

views:

28

answers:

3

I started to version control a directory as follows.

git init
git add . 

Then, I made modifications, adding/deleting/changing files. After I'm done with that, I run

git status

to get the following results.

#   (use "git add/rm ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
# deleted:    bash/_bash_profile
# deleted:    bash/_bashrc
# modified:   functions.sh
# modified:   readme.txt
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
# bash/bash/
# template/

Now, I can do exactly what 'git status' told me to do.

For deleted file run git rm.

  • git rm bash/bash_profile

For modified/added file run git add

  • git add functions.sh

My question is this : how can I automatize this? I see that git already knows what action to do on the modified files.

  • Is there a git command to do staging every necessary file according to its status? (remove or add)
  • If not, is there any easy way to staging all the files instead of running 'git add' or 'git rm' one by one?
+1  A: 

Yep, there's an easy way:

git add -u

This will add all modifications in the current directory (so run it from the top level of your repo if you want everything). It will not, however, add any untracked files. If you want to do that too, you use:

git add .

which will add all files in the current directory. (That means it'll pick up modifications and untracked files, but not deletions like add -u).

Be sure and inspect git status before and after you do this, to make sure you're getting exactly what you want staged. If you prefer commit -a, be even more careful to inspect the status. It's very easy to add something you didn't mean to commit.

Have a look at the man page for more information.

Jefromi
`git add -A` will do new files, as well as removing and updating like `-u`
bdukes
+2  A: 

If you pass the -a flag when you're committing, all unstaged changes will automatically be staged for you before committing:

git commit -a

If you don't want to commit yet, you can use the -u flag to git-add instead:

git add -u

This updates the staged file set will all changes to tracked files. It doesn't pick up new untracked files, however - for that, you'd want to just git add . again.

Amber
+1  A: 

Enter git-add interactive mode:

git add -i

Then type u*q. This will update, stage all changes and quit.

verhogen