How does git matches blobs to files across commit trees?

前端 未结 2 1125
感动是毒
感动是毒 2021-01-12 09:30

Chapter 3.1 of the the Git book clearly states that only staged files get to be stored as blobs in the commit tree.

If, like a commit object, a blob gets a hash ID t

2条回答
  •  一个人的身影
    2021-01-12 10:03

    You mean, if a file has changed? Well, it actually doesn't matter if the file has changed or not. Each revision points to a tree, that is, the root directory of the project that the revision represents at that monent in time. The tree is a recursive structure that holds the names of more trees (same concept of the root tree) or files. So, you get the name of the tree (a directory) or a file.... and an ID to the content. If the object is a file, you get the content, straight... if the object is a tree, well.. you get another tree with a different structure and content... and so on and so on recursively. Now... each revision points also to its parent revision (or parents, if it's a merge commit). And that revision also holds a tree that of course maps to the content of the project at that moment in time, etc. And voila! no tricks.

    So, what happens if a file changes content? Well.... you will have trees that have the same "names" in the structure of the trees that make up the revisions that you are talking about... but then the IDs will change because the content of the file will change. So, names will be the same, IDs will change. I think you have to use a little bit of git cat-file -p starting with your revisions and then the object IDs (trees, blobs) so that you fully understand what's going on.

提交回复
热议问题