5

enter image description here

From this picture, a commit is a pointer to the root tree which is a pointer to other trees and blobs. But what is a proper view of the index?

Questions:

  • Is it a similar tree-ish with folder structures or just a flat view of blobs?

  • If the index is a tree-ish, is there much difference between a commit and the index?

  • Does the index look more like a full snapshot or a diff?

Cyker
  • 9,946
  • 8
  • 65
  • 93
  • 1
    Check out this answer: http://stackoverflow.com/questions/8366963/decoding-git-index-file-using-c-sharp – loganfsmyth Oct 31 '12 at 20:48
  • @loganfsmyth Maybe you should make this an answer so that it can be accepted? I nearly missed your comment, and the question now stays unanswered. It's not really a duplicate of the previous question, either, although the answer ends up being the same. – user4815162342 Nov 01 '12 at 08:16
  • oof. tough one that I'd like to understand better. can't say the technical doc has quite placed it for me conceptually, and the other answers seem conflicting. – Kay V Mar 18 '22 at 08:48

3 Answers3

3

Conceptually, the index is a tree. It stores the state of HEAD reflecting all changes that have been made with git add. When the commit is made, the index simply becomes the tree in the commit. Are you maybe asking how the index is actually implemented? I would guess that it is indeed a tree, but I'm not certain.

Andy Ross
  • 11,699
  • 1
  • 34
  • 31
  • 2
    It's not actually a tree, as it stores a bunch of other metadata (timestamps, etc.) that are not actually stored into the tree when the commit is made. However, your point that it is conceptually a tree is close - it's stored in a completely different format that doesn't point to subtrees/subindexes (i.e. it's a flat list of all the files with associated metadata), but contains everything needed to actually generate the tree objects at commit time. – twalberg Oct 31 '12 at 20:55
2

Same answer as this question: Decoding Git index file using C#

The Git index file format is described here: http://git.kernel.org/?p=git/git.git;a=blob;f=Documentation/technical/index-format.txt;hb=HEAD

Community
  • 1
  • 1
loganfsmyth
  • 156,129
  • 30
  • 331
  • 251
1

Index is a collection of staging files. Or we can say all added files. Cache is the obsolete name of index which for me is easier to understand.

After you commit, the index becomes HEAD which is the head of current branch.

If you want to discard one file in index, you can use $git reset HEAD <filename> to do it.

Alex
  • 81
  • 6