A few questions on this, but none I can find with an unambiguous minimal example. Let's say we want to apply a commit from a particular branch to multiple branches without the legacy commits that preceded the patch commit. E.g.
mkdir cherry_test
cd cherry_test
git init
printf "one\ntwo\nfour\n" > file.txt
git add file.txt; git commit -m 'master: 1'
git branch dev
echo five >> file.txt
git add file.txt; git commit -m 'master: 2'
git checkout dev
echo FIVE >> file.txt
git add file.txt; git commit -m 'dev: 3'
echo SIX >> file.txt
git add file.txt; git commit -m 'dev: 4'
Now lets do a patch to fill the gap (insert the missing line for 'three'):
perl -0777 -i -pe 's/two\nfour/two\nthree\nfour/igs' file.txt
git add file.txt; git commit -m 'dev patch'
At this point I'm unclear how to apply this patch to master without the additional uppercase number commits also patching. Say..
git log
commit d44425da786e161dd066b5db6db8b649b99ba575
author etc
dev patch
Then this answer suggests we need to use git format-patch -1 d44425da
. But then how to merge this with master
and other branches? My efforts all seem to result in previous dev
commits also merging across.