2

So I have a situation with a master and a bugfix branch that continues it. I tried squashing some commits on master and then rebasing bugfix on it but I got merge conflicts. What is the proper way to do it ? I work locally and there is no remote.

It looks like this :

A - B - C - D - E - F [master]
                     \                 
                      G - H - I - J - K [bugfix]

I want to squash A - B - C - D - E - F and still have bugfix continuing the squashed master branch.

ElefEnt
  • 2,027
  • 1
  • 16
  • 20
  • 2
    To get a helpful answer, you should tell us more. Tell us what part (if any) of your repo's history has been pushed to a shared remote, and perhaps add an ASCII commit graph (see [this](http://stackoverflow.com/questions/25488138/move-initial-commits-off-master-to-another-branch-in-git/25490288#25490288), for instance) that describes your recent history. – jub0bs Jan 09 '15 at 18:02

1 Answers1

5

Jubob's point about shared history is a very important one, as rebasing or squashing shared commits is strongly discouraged.

I will assume that you are working with local commits.

Suppose you started with this:

[master] A---B---C---D
                      \
[bugfix]               1---2---3

and you decided to squash B, C and D into a new commit D'

[master] A---D'
          \
[bugfix]   B---C---D---1---2---3

Note that commits B, C and D remain in the bugfix branch. If you simply rebase bugfix onto master, Git will try to do this:

[master] A---D'
              \
[bugfix]       B---C---D---1---2---3

But the changes introduced by B, C and D are already contained in D'. What you really want to end up with is this:

[master] A---D'
              \
[bugfix]       1---2---3

You can accomplish this with the --onto option of rebase:

git rebase --onto master D bugfix

D should be the latest commit in bugfix that should not be included when rebasing.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257