Understanding Git commits is complex, and people have varying mental models. A poll revealed 51% think of commits as diffs (changes between versions), 42% as snapshots (current state of files), and only 4% as a history of previous commits.
Internally, Git stores commits as snapshots, facilitating faster checkout times. However, it also employs packfiles to compress data, storing files as deltas (differences) to save space.
Despite this snapshot-based implementation, Git diffs are calculated by reconstructing snapshots from deltas and comparing them.
A common "wrong" mental model is perceiving commits as diffs from the previous commit, which while inaccurate, can still be useful in daily usage.
The most common mental model, considering commits as diffs, aligns with the typical focus on code changes. Other models, such as snapshots, are useful for understanding file moves and merge commits.
Additionally, people may associate commits with extra information (e.g., emails, conversations) or view them as "before" and "after" states.
jvns.ca
jvns.ca
Create attached notes ...
