merge without merged branch commits history sourcetree

16,619

That means the merge is a fast-forward one: it simply moves master HEAD to feature branch HEAD.

The blog post "Merge or Rebase?" (August 2012) mentions:

You can turn fast-forward merges off in SourceTree so that a merge commit is always created if you want - check the 'Create a commit' option in the Merge dialog or set it globally in Preferences > Git.]

Note: if you are using git-flow with SourceTree, then the merge would always be a fast-forward one if fast-forward is possible: see this thread.

The screenshot added by the OP reveals a non-fast-forward merge, with:

  • a merge commit in master history
  • commits done in feature branch

So A-D is in master, while B-C remain in feature branch: you don't have to "remove" B-C from master history.
The current branch (master) only has A-D. The feature commits are only visible as a context, to explain where the merge commit D is coming from.


Note: this (the merge commit) is represented in GitHub with both parents, meaning including the latest commit of the the merged branch: it is a "feature" from GitHub, not an accurate representation of master history.

See for instance the commits in the master branch of the Git repo itself: each merge commit is followed by one commit from the merged branch.

In the case of the second screenshot, GitHub displays the commits from the merged branch, but those commits aren't part of the history of master (a git log master wouldn't list them).
It is a feature from GitHub, not an exact view of the master log.

Note bis: those merged commits are displayed by GitHub according to their date.
If they are recent, you see them right under the merge commit, if they are older, you see them further down in the commit history list of the master branch.


The OP Asaf Maoz adds in the comments:

when I used smart git I had an option to merge branches and see only one commit in my master branch (similar to those in your link) - the merged commit,

This doesn't seem to be supported yet in ST (see the ST forum).
Even displaying the name of the current branch isn't there yet (SRCTREE-1925)

I didn't change anything in my github account, so it must be in the ST. maybe this option does not exist in ST

Yes: each tool chose its graphical display of a git log.

Share:
16,619
Asaf Maoz
Author by

Asaf Maoz

Software Dev, Multi langs, BackEnd oriented. Java, PHP, Python, some JS, DB stuff etc etc

Updated on June 04, 2022

Comments

  • Asaf Maoz
    Asaf Maoz almost 2 years

    enter image description here

    I need to merge a feature branch into my master branch in SourceTree.

    Every time I merge the feature branch, I see in the master branch commit history all the feature branch commits history.

    I want to merge the feature branch into my master branch and in the master branch to see only one commit added, the 'merged with branchName' commit, that lists the files changed.

    I had that option in smart git, can it be done in SourceTree? How?

    • A: Commit done in the master branch
    • B,C: Commits done on test_branch branch, shown in the master commits history (these are the ones I want to remove from my master history)
    • D: The merge commit (I want to keep this one)