Search code examples
gitrebase

Git rebase multiple merges/branches


I have a scenario where I have made a branch off master, lets call it A, made some changes. Then had to branch off A, let call it B, and made some more changes. I then merged B into A, so now A has both the commits from A and B.

I now need to rebase branch A onto master and squash the commit from branch B, but when I do this I lose all the changes that were on branch B and only the changes from branch A are there.

I am wondering how do I rebase onto master squash the commits and still have all the changes?


Solution

  • If you want to squash the commits from B, then:

    1. rebase B onto A first
    2. squash B so now it is a single (or similar) commit on top of A
    3. rebase A onto master