On Tue, 25 Mar 2014 01:35:11 -0700 (PDT)
Gabriele Salvati <g.salv...@gmail.com> wrote:
> I'd like to know how git restore files when checkout is executed.
> For each commit git knows the diff (added and deleted lines) with the
> parent commit. If git use only diff it must start from the init and
> go forward until the current commit. This solution could be very
> slowly. I suppose git use different approach for calculating the
> content of a file in a given commit.
> Can someone explain how checkout works?
Git does not store diffs. At least not conceptually.
Instead, conseptually each commit references a full snapshot of the
Hence given a commit, Git works like this:
1. Get the SHA-1 name of the tree object representing the root
directory of the project out of that commit object.
2. Locate, read and parse that tree object to obtain SHA-1 names
of blobs representing snapshots of data of all the top-level
files and SHA-1 names of trees representing the nested
3. The step (2) is then recursively repeated for each nested
As you can see, since in a typical project only a fraction of data is
changed in each commit, this storage format is rather efficient:
most trees and blobs are not changed from commit to commit and so
different commits reference the same data.
But Git goes further than that and when it detects the number of such
"loose" objects in the repository is beyond a certain (configurable)
threshold it packs (using xdelta compression ) most of these objects
into the so-called "pack files" which are indexed archives.
These are not really "diffs" in the `git diff` sense, of course, but
are rather binary deltas as you'd find in a typical compressor/archival
To get better grasp on these concepts I'd really recommend to start
with explanatory guides: , , . And if you find yourself lost
in those you can even start with .
You received this message because you are subscribed to the Google Groups "Git
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email
For more options, visit https://groups.google.com/d/optout.