Search code examples
gitgithubgit-mergegit-branchbranching-and-merging

Githib is putting my branched commits in to my master branch. Is this expected behavior?


I've done some experimenting with git branching and one particular set of commands drastically changed the way my graphs looks like.

The git in question is here: Link to Github

What was being tested:

Look only at the right part of the graph, last 5 commits or so.

  • One branch (branch1) diverged from master.
  • There were 3 changes on the branch1 afterwards.
  • There was 1 change on master afterwards
  • Merge was performed on branch1 with master to "keep up to date with master". So far the graph looked as what expected

  • Merge was performed on masters developement on that branch is finished. This is where the 2 graphs change drastically. I wanted what I have drawn with mspaint, but I got the image below.

What I expected To see a nice graph like on the sketch above the picture

What I got Complete rewrite of the history - commits which were done in the branch now appear in the master.

Questions Is this expected behavior? A rewrite of history was made with merge and all my branch1 commits are now visible in the master which I do not want to happen?

Can I somehow undo this and go to previous stage, to se the nice graphs I have had?

Graph changes after merge

EDIT1 I am starting to think this might just be a github representation bug. I am seeing branch commits on my master branch, which shouldn't be the case - unless someone tells me it is


Solution

  • Merge was using fast-forward

    I am using the follwoing code instead:

    git merge --no-ff
    

    I looked at the documentation on: Attlasian and saw that git merge will use FastForward by default if it can. Allthough not visible from the simple example on the Attlasian, FastForward will change the history in a way that it won't be clear anymore which commit was done in which branch.

    This is a behavour I do not want. In my master branch I want to only keep commits that were actually done in the master branch, not have them mixed up with a certain branch.