Search code examples
gitcommitgit-branchgit-history-graph

Git: how this bifurcation happen?


Situation

  • I have a local Git repo.

enter image description here

  • I have only on branch: master.

  • I used to have another branch but I merged it into master and then deleted it.

  • Such merged and deleted branch bifurcated from fe6263e.

  • 0c81926 was an --amend of c79dc19

  • There is no tag nor any other comming pointing to c79dc19. I understand that if some object was pointing to an ammended commit, such commit would continue to show in the history. But this is not the case.

Questions

  • Why didn't the history line flattened?

  • Why is still c79dc19 showing?

  • How did it happen?

As I mentioned nothing points to it and I did a git -gc to clean up any hanging commit.


Solution

  • There is no tag nor any other [commit] pointing to c79dc19

    That's not what the history shows.

    Try running git show HEAD - it'll show what the two parents of the merge are. It looks from your graph like one is the c79dc19, and that's why it shows up in your history.

    Most likely, either the branch really started at c79dc19 (so that was already on master), or the branch was merged to master as a fast-forward when c79dc19 was its head.


    Worked illustration:

    1. initial state

      fe62 <=master <=HEAD
      
    2. new commit

      fe62 <- c79d <=master <=HEAD
      
    3. checkout new branch

      fe62 <- c79d <=master <=branch <=HEAD
      
    4. amend (on branch) gives a new commit 0c81 which replaces c79d on that branch but doesn't change master

      fe62 <- c79d <=master
           \- 0c81 <=branch <=HEAD