Reputation: 132
Especially in Git Pro (https://git-scm.com/book/en/v2), but also in other sources, a branch is said to be a moveable reference to a commit. As you commit, the current branch (indicated by HEAD) moves forward automatically. Elsewhere, however, you read things such as "the last commit on a branch" or "tip of a branch." Which implies that 1) you can move an existing branch backwards to point at an earlier commit than the latest; and 2) that a branch describes more than a single commit it may reference. To me, it sounds like the branch concept is dumbed down for beginners, but I do not know how to square the different usages. Unless the usage is specific to a command. E.g., git log can handle all commits of a double- or triple-dot range, while git diff only operates on the last two commits in a range.
Upvotes: 0
Views: 44
Reputation: 535057
Elsewhere, however, you read things such as "the last commit on a branch" or "tip of a branch."
Wrongly. It is natural to talk that way, because human beings think of a branch as a succession of commits, a piece of history. But that is not how git thinks of it, and you won’t understand git if you think that way.
1) you can move an existing branch backwards to point at an earlier commit than the latest;
Correct. That is called reset.
2) that a branch describes more than a single commit it may reference
Wrong. A branch is a name pointing to one commit, and that is all it is. HEAD is usually a pointer to one such name, namely the one you are working on now, and thus it points at the same commit. When you make a commit In the normal edit-add-commit workflow, it points back to the HEAD commit, and then the branch name (and HEAD) slide forward to point to the new commit.
(What I just said will be clearer if you also know what a commit is. When you know what a commit is and what a branch is, you know almost all there is to know about git. The rest is just some verbs, of which merge is the hardest, along with the mechanism for communication with another git.)
Upvotes: 1