将提交从一个子树应用到同一存储库中的另一子树

ani*_*144 3 git version-control

我一直在使用 git-p4 将 Perforce 存储库的部分内容克隆到 git 存储库中。我检查的树具有以下 Perforce“分支”结构:

仓库/releaseA
仓库/releaseB
仓库/featureA
仓库/featureB

我的本地 git 存储库中有一堆 git 提交到 featureA 目录;但是,我想将这些提交“rebase”到 featureB 目录中。有没有办法将最初应用于一个目录的一组补丁/提交转换到另一个目录上?

jth*_*ill 5

是的。如果您的提交 repo/featureA影响这将非常简单:

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

git am patches/* -p3 --directory=repo/featureB
Run Code Online (Sandbox Code Playgroud)

你就完成了。

如果您的提交更改了 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
Run Code Online (Sandbox Code Playgroud)

sed -s -i -r -f mystuff.sed patches/*
Run Code Online (Sandbox Code Playgroud)

之前git am。在这种情况下,任何对您没有任何影响的补丁都repo/featureA必须这样做git am --skip