2

I my project I have Master and Branch1. I branched out from Branch1 and created Branch2. Both Branch1 and Branch2 moved forward with commits, Branch1 was remote and Branch2 was local to me. Once all features of Branch1 were complete, all the commits were squashed. After I was done with my changes, I committed my changes to Branch2 and rebased on top of Branch1 by using :

# On branch2
git add . && git commit "my branch"

# On branch1
git pull (to get latest changes and update local copy)

# On branch2
git rebase origin/Branch1

# fixed conflicts (1 file)

git rebase --continue
git push origin Branch2

However when I then go into github.com to create a pull request for my branch (Branch2), it shows 2 commits:

  1. The squashed commit of Branch1

  2. My commit ("my branch" commit message).

I dont understand this behavior. Why does commit of Branch1 show up as a commit on my branch? Is there a way to remove it, i.e have only my commit in my branch?

Matthew Hallatt
  • 1,310
  • 12
  • 24
Beginner
  • 2,643
  • 9
  • 33
  • 51

1 Answers1

0

In a pull request you will see all commits, which are missing in target branch (e.g. master). Those could be shown with git log command with commit range specified (see Using Commit Ranges with Git Log).

$ git log master..origin/branch1 --oneline
c675aeb all commits from branch1 squashed

$ git log master..branch2 --oneline
7be222e my branch
c675aeb all commits from branch1 squashed

GitHub does not care in which branch commit was originally introduced. You have to merge branch1 into master first. Then rebase branch2 on top of master (or merge master into branch2).

Community
  • 1
  • 1
Mykhailo
  • 1,134
  • 2
  • 17
  • 25