A commit in git has a reference to a tree and that tree references blobs or other trees and captures a "snapshot" of the project.
What I am not clear about is how the association is done between a specific commit with the actual files affected by the commit.
Example in my project I have the files README
and notes.txt
.
If I add a new file e.g. contracts.txt
and commit it I would have the new commit XYZ
and if I did git show XYZ
I would see only the file contracts.txt
listed.
But if I do git cat-file -p XYZ
I would see that its associated tree is ABC
which doing git cat-file -p ABC
would show:
blob F123 README
blob A0F8 notes.txt
blob DA03 contract.txt
So I can't tell from this how could we figure out that from these 3 reported blobs reported as part of the tree, only DA03 contract.txt
was added as part of the commit XYZ
.
How is the association done?
Simply: by comparing with the same information from the parent commit. For merges, the comparison is done with all the parents. Only blobs which don't come from either (thus are new files or new versions thereof; in the case of merges, also resolutions of merge conflicts) are shown by
git show
.