0

Git has the following concepts:

  • HEAD pointer (pointer to the top commit on the current branch)
  • index (staging area for changes)
  • working directory (local filesystem)

But what is the term for the data-structure in git that will be updated should I commit some changes?

Ben Aston
  • 53,718
  • 65
  • 205
  • 331

1 Answers1

1

As soon as you commit, HEAD will point to the new commit you've made, which will have the tree contents of your index.

An excellent rundown of this all is available in Pro Git, in the Reset Demystified section

HEAD is a symbolic ref-- that is, a ref that (usually) points to another ref. A branch is a type of ref, and your branch will be updated if you commit while that branch is checked out. However, you can check out things other than branches (tags, and plain commits by id), but then you'll have a "detached HEAD". HEAD will still change when you commit, but you could lose those commits if you switch away.

In summary, the only thing you can guarantee updating when you commit is the symbolic ref HEAD, and possibly your current branch, which is a ref. All other data structures are created anew.

Kevin M Granger
  • 2,375
  • 23
  • 28
  • Yes, but what is the name of the data structure that has been updated by the commit? – Ben Aston Jun 15 '16 at 12:18
  • @BenAston my answer has been updated-- you're probably looking for a `ref`. – Kevin M Granger Jun 15 '16 at 12:23
  • Helpful, thanks. IIUC the reflog contains the refs to the branches, tags etc. So when I commit, the HEAD ref associated with my current branch is updated. But the "git database" must also be updated with the target of the ref? Presumably the ref points at a SHA hash which is an index into this "database". I use "git database" in place of the term I am looking for. – Ben Aston Jun 15 '16 at 12:35
  • A commit, identified by SHA hash, consists of a tree and associated metadata. A tree is also identified by SHA hash and contains references to other trees and blobs (files). Anything "checked in" to git is given a SHA reference-- see [Git Objects](https://git-scm.com/book/en/v2/Git-Internals-Git-Objects) and [Git References](https://git-scm.com/book/en/v2/Git-Internals-Git-References) from Pro Git. – Kevin M Granger Jun 15 '16 at 12:43
  • Thanks. And what is the name of the location these trees reside? The "git filesystem" (based on one of your links)? – Ben Aston Jun 15 '16 at 12:46
  • Are you looking for "repository" or where all git internals are kept? I'm not sure the latter has a well-defined name. – Kevin M Granger Jun 15 '16 at 12:48
  • OK, repository will suffice. Pls add to your answer and I'll accept – Ben Aston Jun 15 '16 at 13:08