epsilones
epsilones

Reputation: 11609

Is a commit a branch in itself ? - git

I hope the following question will not be too general. Plz telle me if not, this post could be migrate elswhere. So, I have read in this really good doc (bottom of page 10) that a commit could be considered as a branch in itself. In what way could it be said like that ? How does a commit support the whole history of a branch (for mathematics minded people, could a commit be thought as fibration (supporting the history of the so-called branch) over some tree)

Upvotes: 1

Views: 104

Answers (2)

David M
David M

Reputation: 4376

I think that's too esoteric a discussion of the "branch" concept, but that's not terribly important.

The effect is that every commit represents a branch whose HEAD is that commit, with the difference from typical branches being that the branch name (which is the SHA-1 of the commit) is immutable. The hash-as-branch-name always points to the hash-as-commit.

Try it yourself with this command: git checkout 2ae907 (where the reference is to some previous commit). You'll get text like this:

Note: checking out '2a9e07'.

You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.

Commits are added to a graph of commits, so every commit is the root of a subgraph that includes all the previous history.

Upvotes: 3

Carl Norum
Carl Norum

Reputation: 224944

In git a commit always includes the complete history of the tree at that point (by including a reference to its parent commit). In that sense, you can consider it a branch. The only difference is that a branch has a symbolic name, so that you don't have to refer to it by its hash.

Upvotes: 1

Related Questions