Git documentation states:
Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment
What does it basically mean "to take a picture"?
Git documentation states:
Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment
What does it basically mean "to take a picture"?
It asks all the files in the repository to stand in a line and say "cheese". Then, an x-ray picture is taken, showing all the binary data.
This binary data is then used to determine the state at which your folder was at that point, in order to re-create it later (on a different location) or to make diff's.
Make a commit and then run git log -1 --pretty=raw
and you will see tree xxxxxx
in the output. The tree is the sha1 of a snapshot of the current git repo . If two trees have the same sha1, we can be sure they have the same contents. You could run git ls-tree sha1
to see what's the tree composed of or what the snapshot has. You will see a list of trees and blobs, sometimes also commits, with their sha1s. A blob refers to a file. A tree refers to a folder. You could run git cat-file -p blob-sha1
or git show blob-sha1
to see the content of the blob. Every blob is a snapshot of a file in different times. If a file is changed, its blob and sha1 changes too. But with the same content, we can always get the same sha1, by git hash-object
. So basically, a commit refers to a tree (the root folder of the git repo) which represents the state of the git repo. A tree is composed of other trees (sub directories) and blobs (files) in the git repo. When we make a commit, it records the state of the git repo, what the folders and files are like at that time. With the commit, we can rebuild the whole git repo which is described by the trees and blobs.