'How does internaly git compose files so quick (just "academic" question)

I have just "academic" question for Git experts.

I could not find anything about how Git actually internaly compose files from all the commits. I could not imagine that it iterate through all commits untill now (go from the very first commit and keep changing/adding/deleting etc. until it have current version).

Wouldn't it be slow for large codebases with MANY commits, many big files etc.? But maybe I am imagine it wrong. Maybe it do the work once in a while and save the "complete picture" after some commits to keep the "composing" fast, so it doesn't need to start from the very beginning, I dont know :) ... something like 'memoization'.

Has anybody here better understanding of what is going on internally in Git when it figuring out current files?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source