3

I have a Git repository as follows:

A-B-F  (master)
|\   
C \    (feature-1)
   D   (feature-2)
    \
     E (feature-3)

Is there any way to rebase automatically all the feature branches (both children and grandchild) to F as follows?

A-B-F (master)
    |\   
    C'\    (feature-1)
       D'  (feature-2)
        \
         E'(feature-3)

I have checked the replies of Rebasing a branch including all its children and How to rebase a series of branches?, but neither they are covering this particular case, nor a definitive answer is given.

Community
  • 1
  • 1
JoKo
  • 152
  • 1
  • 8

1 Answers1

3

The anwser is the same as in the related questions: there is nothing built-in in git for this. You can do this manually as described below. After that you can try to put it in a script...

This is how you do it manually:

git checkout feature-1
git rebase master
git checkout feature-2
git rebase master
git checkout feature-3
git rebase feature-2

to help you on the way starting to script this your self:

git branch --contains <sha-1> | xargs -n 1 | grep -v "\*" | grep -v master

will give you a list of all branches that contain commit <sha-1>. Then you can look at this question to find code on how to find first-level descendants... Putting these two informations together; you'll be able to scripts what you want.

Community
  • 1
  • 1
Chris Maes
  • 35,025
  • 12
  • 111
  • 136
  • Thanks, this is what I am currently doing. I have specifically asked for an automated way... – JoKo Nov 18 '15 at 18:29
  • as I told you, there is nothing in git that will allow that; you need to define clearly what you want to automate and how... what branches will need to be rebased; and on which branch...? You'll have to write that yourself; but I can help you on the way if necessary – Chris Maes Nov 18 '15 at 18:31
  • ok, how about a more automatic way, such as find all the children of a specific commit (A) and rebase them to another specific commit (F). If there are grandchildren, rebase them to their new parents etc. – JoKo Nov 18 '15 at 18:34
  • @joko if my answer helped you, please consider accepting it. – Chris Maes Jan 19 '16 at 15:05