0

I use SourceTree. I have created a branch B from branch A.

Then I made 3 commits to branch B, checked out the branch A and saw someone committed something there.

After that I merged my branch B to branch A. But instead of "merge", I saw my commits duplicated on branch A!

The code of branch A is actually what I wanted it to be, but I didn't want it to duplicate my commits, I just wanted to see how my branch B nicely merges into branch A.

Here is a screenshot of SourceTree log. As you can see four red arrows and four green arrows point to duplicated commits I was talking about: enter image description here

Why did it duplicate instead of merging? Thank you.

Captain Man
  • 6,997
  • 6
  • 48
  • 74
shal
  • 2,854
  • 4
  • 20
  • 31
  • Are you positive it's not a display error in SourceTree? Check the Git host. – Bondt Apr 25 '16 at 13:30
  • Thanks for the additional screenshot. It does appear that your commits have been duplicated. Just to be sure, can you get the ID of the same commit in each branch? If they are the same commit appearing in two branches then they should have the same ID. – Adam Nierzad Apr 25 '16 at 14:05
  • 1
    Also, at any point has yourself or another developer used `rebase`? This will give the commits new ID's and cause them to be treated as though they aren't the same commit. – Adam Nierzad Apr 25 '16 at 14:08

2 Answers2

1

By the looks of it, someone rebased your branch shaimu-hud-features onto the commit with message add "EXTRA_BONUS_ROUND_COINS" key... and pushed to the remote branch release/Release-2.2.0. The only reason you're seeing duplicate commits is because you are looking at All Branches (see drop-down on the top-left corner of your screenshot).

That being said, if at some point someone merges release/Release-2.2.0 into shaimu-hud-features, you will have duplicate commits. They're not exactly duplicate, because they have different hashes, but they introduce the same set of changes and have the same message.

Talk to your team to understand why they've rebased your commits. In the future, avoid rebasing one feature branch onto another, which will cause "duplicate" commits if they're both merged into mainline.

alextercete
  • 4,871
  • 3
  • 22
  • 36
-1

After that I merged my branch B to branch A. But instead of "merge", I saw my commits duplicated on branch A!

Your commits cant be duplicated. you miss something. can you please attach screenshot.

Once you merge branches they should have the code of the 2 branches. Your commit history will include all of them in the same branch.


Each |\ is a merge. enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • Each `*` is actually a commit. – Adam Nierzad Apr 25 '16 at 13:43
  • This is how Sourcetree display the commits. Choose the current branch from the drop down and you will see only the current branch commits – CodeWizard Apr 25 '16 at 14:00
  • The current value in our screenshot is All branches – CodeWizard Apr 25 '16 at 14:00
  • You can see that the lines do not "merge". Each commits are on separate branches. – CodeWizard Apr 25 '16 at 14:01
  • Exactly! I merged these two as I described, but instead it just copied commits from one branch to another! This is exactly what my question was about! Why didn't it merge? Well, I turned on SourceTree's option "Do not fast forward when merging, always create commit" and I hope it's going to prevent this kind of stuff in the future. – shal Apr 26 '16 at 05:55