Apply commits from one subtree to another in the same repo

I used git -p4 to clone repo parts in Perforce into a git repository. The tree I checked has the following Perforce branch structure:

repo / releaseA
repo / releaseB
repo / featureA
repo / featureB

I have a bunch of git that compiles in my local git repository to the featureA directory; however, I would like to β€œreinstall” those commits into the featureB directory. Is there a way to translate a set of fixes / commits that were originally applied to one directory on another?

+1
source share
2 answers

. repo/featureA, :

mkdir patches
git format-patch -o patches master..my_featureA_branch

git am patches/* -p3 --directory=repo/featureB

.

repo/featureA, ,

cat >mystuff.sed <<\EOD
/^(From [0-9a-f]{40}|diff --git )/!{H;$!d}
x
/^From /b
${h;s,.*--,--,;x}
\,^diff[^\n]* [ab]/repo/featureA/,!{$!d;x;b}
${p;x}
EOD

sed -s -i -r -f mystuff.sed patches/*

git am. , repo/featureA, git am --skip .

+3
  • ,

    git cherry-pick <commit-id>

  • , C1 Cx, rebase -onto

    git rebase --onto featureB C1 Cx

0

All Articles