'"Re-parenting" GIT feature branch based on another
I am hoping someone knows the git-fu required to untangle a branch mess.
I have a feature branch - FB2 - whose parent is FB1, which in turn originated from master.
Bad news: I need to retarget FB2 on top of master as it needs to ship before FB1, without any of the commits from FB1.
Good news: There are few code changes in FB2 that directly interact with changesets from FB1. However, there are dozens and dozens of commits from pull requests over many tickets (~75) from both FB1 and FB2.
I'm looking for the least painful way to find and incorporate only the commits which were committed directly to FB2. Alternatively, a way to alter the existing FB2 branch to retarget master and remove all the commits that originated from FB1.
brute force cherry picking or rebasing will take forever and be error prone.
"git rebase --onto master FB1" didn't seem to work in a test. The changes from FB1 were still present in FB2.
Thanks!
Similar to the diagram here:
# CURRENT
A--B--C--D // master
\
E--F--G // FB1
\
H--I--J // FB2
# DESIRED
H--I--J // FB2
/ \
A--B--C--D M // merged
\
E--F--G // FB1
Solution 1:[1]
Have you had any re-merges between FB1 and FB2 ? Or you just branched of fb1 and fb2 then had its own history? if so :
you may try creating the patch between commits G and J:
git diff #G..#J > mypatch.patch
then create a new branch where you actually want to start from and apply the patch:
git apply mypatch.patch
However, if files do not exist on the new target branch, the patch fill not apply cleanly.
for that you may first want to do :
git diff --name-status #G..#J
to identify what actual files changed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dmitry |
