1

I have made two branches: master and test. In test branch I have two commit in my test branch and I expect to see two branches in my graph view, but I see one straight graph and seems it has one branch.

enter image description here

Also this is my git log:

enter image description here

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Ata barzegar
  • 116
  • 1
  • 12
  • 1
    It's because what you expect branches to be is different from what branches actually are. Your two branches are here, and the graph represents accurately what you have : two branches, one of which is two commits ahead of the other. Branches, like tags, are just pointers to *one* position on the commit tree. It's **not** a series of commits. Check the [doc](https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell). – Romain Valeri Jul 22 '22 at 07:47
  • Not *precisely* a duplicate, but see [How to find the nearest parent of a Git branch](https://stackoverflow.com/q/3161204/1256452) – torek Jul 22 '22 at 19:52

1 Answers1

1

This is a bit of a trick question, or riddle, but: When is a branch not a branch?

Possible answers:

  • When it's a twig.
  • When it's a trunk.
  • When it's in Git.

See also What exactly do we mean by "branch"?

The fact is that a Git commit graph is simply a Directed Acyclic Graph or DAG. It's possible to draw this DAG in many ways:

*   (test)
|
*
 \
  *  (master)
  |
  *
  |
  *

or:

A--B--C   <-- master
       \
        D--E   <-- test

or, indeed, as what you've just seen: a straight line with two labels on it. We could even draw it as:

         E   <-- test
        /
A      D
 \    /
  B--C   <-- master

if we like. All these drawings are the same, in the same way that a donut and a coffee cup are the same shape. (This explains why topologists' teeth are so bad. Also, read the comments under the video.)

(Although it's probably too late, the TL;DR is: your expectation is wrong.)

torek
  • 448,244
  • 59
  • 642
  • 775