We ran at work into the quite tricky problem to move the “pure” implementation of a feature to some other branch (a quickfix-release) without adding those features/bugfixes from the current master-branch. The feature branch was created some while ago and meanwhile updated from time to time with origin/master.
Discussed options were:
* manually copy the changes (since it was one directory and some minor adjustments in other CMakeLists.txts and some calls) –> much work, very error prone in terms of “Oh, I missed something”
* move to HEAD@target-branch and cherry-pick one-by-one all feature-commits (without merge-commits) –> lots of work, because 15+ commits
* some Git-way –> preferred by me, but I neve did something similar before – so: totally unknown
I chose the third option and tinkered in parallel while someone else tried the other path.
0. created “fake-feature-branch” on HEAD of the feature-branch
1. merged current state master-branch to it
2. created a diff as patch-file between HEAD@master and HEAD@”fake-feature-branch” by:
git diff fromHash toHash --binary > ../binary.patch
(–binary is important; else added ressources will be missing)
4. switch to HEAD@targetBranch
5. apply the patch (and suppress whitespace-errors) by:
git apply --whitespace=fix ../binary.patch
6. eventually fix conflicts if necessary
Yay, two commands to save the day! Around 170 files were affected, so manually doing the application of the changes was out of scope for me. There had to be a feasible Git-solution.