3

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)
Lernkurve
  • 20,203
  • 28
  • 86
  • 118
Asaf Maoz
  • 675
  • 3
  • 6
  • 23
  • The simple merge without commit history is currently not supported by ST. – Asaf Maoz May 14 '14 at 07:15
  • Not sure how to do it in SourceTree (never used it), or if it's even possible, but it sounds like you want `git merge --squash`... – twalberg May 19 '14 at 15:29

1 Answers1

3

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I turned fast-forward merges off, I get the 'merged with branchName' commit, but I also see the merged branch commit history- which I don't need. I want my master branch to have only the 'merged with branchName' commits – Asaf Maoz May 13 '14 at 07:56
  • 1
    @AsafMaoz can you add a screenshot of what you see? – VonC May 13 '14 at 07:58
  • tnx for helping. I added a screen shot of ST – Asaf Maoz May 13 '14 at 08:07
  • When I push master to github I see B-C as commits on my master branch commits history – Asaf Maoz May 13 '14 at 08:16
  • @AsafMaoz can you tell me what is the url of that GitHub repo? – VonC May 13 '14 at 08:18
  • I added a screen shot for the github commits history of master branch – Asaf Maoz May 13 '14 at 08:21
  • @AsafMaoz the url would have helped too. – VonC May 13 '14 at 08:24
  • Its private so would not help much... Is the screen shot not enough? let me know what other info you need... – Asaf Maoz May 13 '14 at 08:25
  • @AsafMaoz Got it. It is a "feature" from GitHub, see my edited answer. – VonC May 13 '14 at 08:34
  • You can see in the link you added that there is only one commit- the merge commit. You dont actually see commits done in the merged branches. That is what I need. – Asaf Maoz May 13 '14 at 08:39
  • @AsafMaoz yes, you do. But those commits on the merge branch are displayed 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. But you *do* see them, I promise. It is a GitHub presentation feature. – VonC May 13 '14 at 08:40
  • Nope. sorry, but 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, I didn't change anything in my github account, so it must be in the ST. maybe this option does not exist in ST. There currently isn't an option to force push either(but that's a different thread...). – Asaf Maoz May 13 '14 at 08:47
  • @AsafMaoz this has nothing to do with ST: you see commits in GitHub because GitHub *choose* to display them. And you see those commits in ST *not* as part of the history of `master`, but in a separate (merged) branch. The way GitHub and ST display the history of master are two different things. In both cases though, those commits *are not* part of the history of `master`. – VonC May 13 '14 at 09:12
  • @AsafMaoz I have edited my answer (last part) to address your last comment. – VonC May 13 '14 at 11:52