git update-index

CommandNew filesChanged filesDeleted files
Alice/> git init
Initialized empty Git repository in /home/rene/github/github/git-internals/repos/update-index/Alice/.git/
snap no: 1

First, Alice creates two files: foo-bar-baz.txt and …

Alice/> printf "foo\nbar\nbaz"   > foo-bar-baz.txt
snap no: 2

… one-two-three.txt.

Alice/> printf "one\ntwo\nthree" > one-two-three.txt
snap no: 3

She adds foo-bar-baz.txt to the index:

Alice/> git update-index --add foo-bar-baz.txt

The name of the file is added to .git/index and an according blob-object is created under ./git/objects

snap no: 4

She also addes one-two-three.txt to the index

Alice/> git update-index --add one-two-three.txt
snap no: 5
.git/index

Trying to remove a file from the index does not change the repository …

Alice/> git update-index --remove foo-bar-baz.txt

… because the file foo-bar-baz.txt is still existant.

snap no: 6

So, the file is removed …

Alice/> rm foo-bar-baz.txt
snap no: 7

… and then the index is updated

Alice/> git update-index --remove foo-bar-baz.txt

Note: the object file is still in the ./git/objects directory.

snap no: 8
.git/index