A commit in Git: Is it a snapshot/state/image or is it a change/diff/patch/delta?

后端 未结 2 563
深忆病人
深忆病人 2020-12-16 04:17
  • Some operations in Git (e.g. checkout) appear to assume that a commit is a snapshot or state of the working tree.
  • Other operations in Git (e.g. <
2条回答
  •  不知归路
    2020-12-16 04:51

    A commit is a snapshot state. When you do git diff, it calculates the diff to the parent. This is why there can be multiple parents (the case when there is a merge). Internally, there is delta compression going on, but the versioning model isn't patch-based.

    A central concept in git is the index. This is a big object containing the tree of objects being tracked. Changes are staged when they propagate from the working copy to the index; this puts the index into a modified state. The commit operation turns that state into a new commit.

提交回复
热议问题