my understanding of the principle of git is that every time git commit, it generates a tree object, a parent object (if not submitted for the first time), and a commit object. The top-level tree corresponds to the entire working directory, and there are blob and tree objects under the tree, all of which are a string of hash values pointing to the corresponding content. When a file changes, the snapshot will be saved again. If the file has not changed, the snapshot retained is still the last.
all the data is saved in objects, so don"t I have to generate a new file every time I submit (because the commit is different each time)? Then the content of the objects file of the whole project will become more and more after numerous submissions.
but I took a look at the objects in the project and there aren"t many files. Why is that? And as far as I understand it, each time commit generates only one file name in objects, which is the first two digits of each commit hash value, but actually generates three folders? And why is that?
< hr > split line:
I built a new git repository locally, and there is only one txt file under the folder
commitlog
treehashba65d8..hash:
blobhashhash
the last reference points to the contents of the file.
through the above operations, I personally understand as follows:
there are three objects in git. Tree, blob and commit, have passed the test. I think these three objects are not equal to each other. After submitting a commit, a commit object is generated. There is a top-level tree object under this commit object, and then there are tree objects or blob objects under the tree object. The lowest blob object is the content of the file
and git finds the corresponding file according to the hash value of these objects and records the status of each commit. Every time the commit is submitted, the changed file saves a new snapshot. The (hash), unchanged file still retains the original snapshot (hash) value.