Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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

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

like image 831
jpd Avatar asked Jul 26 '16 09:07

jpd


2 Answers

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

like image 104
berliner Avatar answered Nov 14 '22 23:11

berliner


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.

like image 41
AnoE Avatar answered Nov 14 '22 23:11

AnoE