1

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)

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

4 Comments

yes but where the data related to the link between one commit to its parent is stored ?
git implements a Directed Acyclic Graph to store the relationship between commits. How the DAG is implemented isn't important to understanding the abstract notion of how commits are related to one another.
@Newben: Every commit contains a reference to its parent(s). You can see it with e.g. git show --format=raw <commitid> - it will list the ID of the parent commit. Note that a commit may have more than one parent (merge commit), or none (initial commit).
@Newben: The object format is described in the User's Manual in the storage format section and in the object database section. That pretty much describes loose objects. The pack format is described here, and the index format here.
1

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.

3 Comments

so if I understood well, each commit stores for each 'file' of it tree a serie of references for successive diff files, the composition of which leads to this 'file' ?
Not exactly. If you read Pro Git, I'm sure you'll be enlightened.
It would probably be more accurate to say that a commit contains a snapshot of the tree at that point rather than the complete history. History is pretty much by definition a series of events rather than a single event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.