tags:

views:

158

answers:

3

I was assuming that both work in the same way. Both add every file onto index. But I seem wrong.

  • What's the difference between git add . and git add -u?
+5  A: 

Like the manual says: git add . will add all files in you current directory, while git add -u . will only add those already being tracked.

honk
`add -u` will also stage deletions.
Charles Bailey
only if the deleted file was tracked ;)
honk
add -u is the commit -a equivalent, sort of(in files it operates on).
Lakshman Prasad
@Benjamin Bannier: If the deleted file wasn't tracked then there's nothing to be deleted from the staging area anyway?
Charles Bailey
@Charles Bailey exactly ;)
honk
+2  A: 

git add documentaiton

git add . 

add all files from the current directory

git add -u 

only update files currently being tracked.

Swingley
+2  A: 

It is one of git gotcha mentioned here

git add . only add what is there, not what has been deleted (if tracked).

git add .
git commit
git status
//hey! why didn't it commit my deletes?, Oh yeah, silly me
git add -u
git commit --amend

git add -A would take care of both steps...

VonC
Thanks for your answer and an example. The "hey!" line really helps me.
TK
@TK: yes, Benjol (http://stackoverflow.com/users/11410/benjol)'s example is a good one.
VonC