Git: Test combination of two feature branches
Asked Answered
M

1

8

I have a Git branch for each feature. However, sometimes, when developing in branch A, I would like to test how A would behave if B was applied also.

At the moment, I use this:

git checkout A
git branch base
git merge B
git reset --mixed base
git branch -D base

Is there a shorter way to do this?

Additionally: what if A and B do not share the same ancestor?

o -- o -- o [A]
 \-- x -- o [v1_0]
           \ -- b1 -- b2 -- o [B]

How could I do something like this more easily?

git checkout A
git branch ABase
git cherry-pick v1_0..B   // only applying b1,b2 not x
git reset --mixed ABase
git branch -D ABase
Matz answered 4/9, 2015 at 10:22 Comment(2)
git merge v1_0..B? Don't you mean git cherry-pick v1_0..B instead?Interinsurance
@Jubobs: Yes I will change it to cherry-pick. Also I reset to A afterwardsMatz
W
1

One possibility:

$ git checkout $(git rev-parse A)
$ git merge B
$ git checkout - # returns you to wherever you were before

This checks out the underlying revision (leaving you in a detached HEAD state) and makes changes from there. The benefit of this approach would be that you no longer need to create and delete a branch. This doesn't make the workflow much shorter but you should be able to wrap this in a function, take a few arguments, and reuse it.

As for your second question: you should be able to use merge-base to determine the common ancestor(s) and use that to either merge or cherry-pick commits (thinking back to having a function that does this work for you).

Windlass answered 9/9, 2015 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.