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
schoetbi
  • 9,843
  • 7
  • 44
  • 70

1 Answers1

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).

Whymarrh
  • 11,635
  • 13
  • 55
  • 96