The answer to this is Merkle Tree. A Merkle Tree is a tree where all the non-leaf nodes stores hash of its child nodes.
Git stores the files and directories in UNIX file system. Git basically generates hash of the content of the files. And it uses this hash in its parent node that points to a file/directory. Small change in a file will not result in comparing the whole file. Certainly, any change in the file will result in new hash and then it needs to be updated back till root node.
When we do git pull, it compare the hash of the root node on the remote to the hash of the root on local, if it is different then it checks in child nodes that which node’s hash is changed and keep doing that untill it find the exact node that is changed and it sends that specific change over network.
For more system design related content, follow me on LinkedIn.
#datastructures #git #systemdesign