4 ms·
That’s not right. A branch is a single pointer to a single commit. Just open your .git folder. It’s then Git itself that follows that commit’s pointer to its pa
by lakpan 3y ago
That’s not right. A branch is a single pointer to a single commit. Just open your .git folder. It’s then Git itself that follows that commit’s pointer to its parent(s).
The branch, like the tag, is a single reference to a commit.
Do this:
$ cat .git/refs/heads/main
- Buttons840 3y agoIt seems accurate enough to say the branch includes all the parents of the pointed to commit. It's a matter of definition, but both definitions are technically accurate. (Also, note the path you ask us to cat does not contain the word "branch". You refer to how things are stored to support your definition, but the way things are stored doesn't use the term "branch".)
- Espressosaurus 3y agoThe question was "what do you think is the most natural way to think about it", not "how does git represent it".
- lakpan 3y agoWhat? If you’re looking for “the most natural” then you’ll find it in the name. You can’t “explain” branch by using a synonym. Plus that definition describes both tags and branches, how do you tell them apart? It’s clearly lacking. Actually that definition fits commits too. I’d rather use these: Branch: a pointer that advances Tag: a permanent pointer Commit/hash: an even more permanent pointer (because even a force can’t change it) that also describes the changes.
- seba_dos1 3y agoTechnically, you're right. Practically however, it does make sense to implicitly dereference the branch you're talking about to the commit it points to. Asking "is this commit on that branch?" is semantically equivalent to "is this commit reachable from the commit that branch points to?". That said, it only makes sense to make such implicit mental shortcuts once you're already comfortable with git's data model. If you're not and you're still learning it, it's only going to confuse you.
- lakpan 3y agoTo be honest, describing a branch the wrong way is only going to confuse people more. The “dots on the line” visualization is pretty clear: you can have any number of branches pointing to a specific dot/commit. How do you add “branches” without fundamentally breaking that concept? When you create a branch, you’re not copying the line, you’re just adding a pointer.