What is the difference between "git add" and "git update-index"?
Under what circumstances would I use one of these commands or the other?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With