Git: merging feature branches into an earlier part of the master line

I'm sure this has been asked before, but I'm not even sure what conditions I'm looking for.

I have a branch structure that looks like this:

startoftime -> A -> B -> C -> D (master head)
                    |
                    -> X -> Y (feature1 head)(tag T)
                    |
                    -> Q -> R (feature2 head)

      

Basically, I created two feature branches from commit B and did development in them. The chapter of one of them has a tag that reflects its shared history from the original root. Now I want to roll them back into the master, but ideally I would like them to appear in the story before the new material on the master, and not after that, so leaving the current main head where it is. Ideally I would like:

startoftime -> A -> B -> X -> Y -> Q -> R -> C -> D (master head)
                              |
                            (tag T)

      

What concepts or commands should I be looking at here?

There is speculation that it rebase

may be that I am here. All three of these branches have already been pushed back to my remote, although I can guarantee that no one but me has pulled / checked out of it. Can I use rebase?

Thank.

+1


source to share


2 answers


Rebases are not a problem if no one else is using your branches. It doesn't matter if it's "remote" or not. You will just need to use --force

on next click.



Speaking of which, I would like to encourage you to reconsider just using merge. Your history will show a graph of when the features were developed, but it will also more accurately reflect the history of you working in parallel, as well as when you integrate it into your main branch. If you rebase, your current one Q

will be different from Q

when you originally worked on it, perhaps to the point that it doesn't work as you'd expect if you ever have to revert to it. It also makes it easy to remove feature1 or feature2 if needed for any reason.

+3


source


Just to be complete (and I agree with karl Bielefeldt's answer ), a solution using rebase would be:

git checkout feature2
git rebase feature1
git checkout master
git rebase --onto feature2 B D

      



( See here for an example git rebase --onto

)

0


source







All Articles