3 ms·
commit == snapshot + reference to parent commit
by gjvc 3y ago
commit == snapshot + reference to parent commit
- kelnos 3y agoHow it's implemented in git, yes, but I don't think that's useful as a mental model. A commit is a change -- diff -- from the previous version of the state of the repository. When I make a commit, I don't think of it as making a copy of my repository, adding my changes, and storing the entire result (though that's exactly what many people used to do before version control was common!). I think of it as storing the change that I made, and only the change.
- AndrewDucker 3y agoYou may think of it that way, but it is actually storing a snapshot of the current state, with a pointer to the previous state. And that's what a commit is, it's a snapshot.
- kelnos 3y agoI'm well aware of how it actually works, but I don't think git's implementation details are a useful mental model of source control in general.
- gjvc 3y agoHow it's implemented in git, yes, but I don't think that's useful as a mental model. pointers to content, right. "Remember, git does not track changes, it tracks content." I kept telling myself when I learned how the system works. As conceptually great as that is, in the early days of learning git, I found the terminology in the command-line interface VERY off-putting, and it played havoc with my mental model. (I say this lest you think I'm unconditionally cheerleading git or the implementation.) BTW, perhaps because effective use of a VCS is so vital to programming without stress, people tend to think they can learn it on the fly, which leads to all sorts of insecurities about not really knowing how a certain operation works. (I've worked in toxic places, so seen how fear has myriad weird manifestations.) Anyway, not intending to disagree or correct you, just offering my experience while I suffer winter flu.