0

Can somebody please explain the concept of snapshots in git. I do understand who data can be stored as a series of changesets, but how is that different from snaphots in git. and why is it better this way?

The basic Git workflow goes something like this: (As taken from git documentation)

  1. You modify files in your working directory.
  2. You stage the files, adding snapshots of them to your staging area.
  3. You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.
CharlesB
  • 86,532
  • 28
  • 194
  • 218
ssayyed
  • 766
  • 1
  • 8
  • 13

2 Answers2

0

git commit objects are essentially snapshots you are talking about.

Every commit in git represents snapshot (or state) of the whole tree as it was in that moment of time. Another commit makes another snapshot and so on.

You can always rewind state of the whole tree by checking out to commit: git checkout commit_id - it is almost like time machine.

When you git add files you don't really make snapshots, you simply put those files into index to become part of next commit, such that when you actually commit, commit object will simply refer to those files that were git add-ed (actually, those files are blobs organized with help of trees).

mvp
  • 111,019
  • 13
  • 122
  • 148
0

I think the documentation is very bad.

You are familiar with the work tree, which is just the files as you see them, the staging area or index is like a draft, and the final commit is the snapshot.

FelipeC
  • 9,123
  • 4
  • 44
  • 38