jpd
jpd

Reputation: 723

What is the difference between "git add" and "git update-index"

What is the difference between "git add" and "git update-index"?

Under what circumstances would I use one of these commands or the other?

Upvotes: 12

Views: 3637

Answers (2)

berliner
berliner

Reputation: 1955

Basically, update-index is a plumbing command - it means, low-level. git add internally uses update-index. I believe, that

git add <file> is the same as git update-index --add <file>

One of the circumstances, when I use update-index, is when you have a change to a file, which you don't want to commit - in this case you can run

git update-index --assume-unchanged <file>

So if you run git status after that, you'll see, that file not in the list of changed files.

More here How to manage configuration files when collaborating?

and here http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html

Upvotes: 7

AnoE
AnoE

Reputation: 8345

To quote git help update-index:

See also git-add(1) for a more user-friendly way to do some of the most common operations on the index.

So git add is the thing you normally use, while git update-index is the more powerful variant that also requires more knowledge on your side.

NB. It really pays off to get used to the git help command, the help pages of git are excellent.

Upvotes: 4

Related Questions