Reset branches with sub-branches at the same time

I often have branches on a branch that I want to reinstall on mainline. Consider this:

* (Mainline)
*
*
| * (topicA_Branch3)
| *
| *
| * (topicA_Branch2)
| *
| *
| * (topicA_Branch1)
| *
| *
|/
*
*

I want to move all three of these branches topicAto mainline. I currently know two ways to do this:

  • topicA_Branch3Run the command during git rebase Mainline.

    a. At this point, I would have to delete topicA_Branch1and 2manually re-create the branches on the correct commit on now rebased topicA_Branch3.

  • Another way would be to make three separate commands:

    a. While on topicA_Branch1, do it git rebase Mainline.

    b. git rebase --onto topicABranch1 <topicA_Branch1-old-SHA> topicABranch2

    with. git rebase --onto topicABranch2 <topicA_Branch2-old-SHA> topicABranch3

    e. It's kind of bulky ...

Is there a team that I want to reinstall the branch and bring it under the branches?

To be clear, I want to end up with:

* (topicA_Branch3)
*
*
* (topicA_Branch2)
*
*
* (topicA_Branch1)
*
*
* (Mainline)
*
*
*
*
+4
2

, , , . . , , -

for i in topicA_Branch1 topicA_Branch2 topicA_Branch3
do
    git branch $i._OrIg_ $i
done
# First branch directly
git rebase --onto Mainline topicA_Branch1
# Remaining branches
git rebase --onto topicA_Branch1 topicA_Branch1._OrIg_ topicA_Branch2
git rebase --onto topicA_Branch2 topicA_Branch2._OrIg_ topicA_Branch3

, , , *._OrIg_. script .

. , ,

 git rev-list --reverse --simplify-by-decoration Mainline..topicA_BranchN \
 | git name-rev --stdin --name-only

topicA_BranchN, . topicA_Branch3 .

0

git filter-branch --parent-filter. - :

git filter-branch --parent-filter 'sed -e "s/X/Y/"' --tag-name-filter cat -- branchA branchB branchC

X , , , Y HEAD Mainline Mainline...

0

Source: https://habr.com/ru/post/1534317/


All Articles