Home > other >  When I merge branchA to branchB, would the commits in branchB be updated with the ones I did previou
When I merge branchA to branchB, would the commits in branchB be updated with the ones I did previou

Time:11-29

I encountered this question while building an application with multiple branches

I was expecting not only the code but also the commits I made previously in a previous branch to get merged into a new branch

CodePudding user response:

A merge would only create one commit on branchB with two parents.

b--b--b--M (branchB)
        /
 a--a--a   (branchA)

If you want the commit from branchA to be part of branchB, you would need to rebase branchA on top of branchB first, before merging A to B.

git rebase --onto branchB firstCommitofA~..branchA
git switch branchB
git merge branchA

That is:

b--b--b--a'--a'--a' (branchB)
                    (branchA)

CodePudding user response:

Alternatively try git merge --no-ff

  •  Tags:  
  • git
  • Related