将提交从一个子树提交到同一仓库中的另一个子树 [英] Applying commits from one subtree to another in same repo
问题描述
我一直在使用git-p4将Perforce存储库的一部分克隆到git存储库中.我检出的树具有以下Perforce分支"结构:
I've been using git-p4 to clone parts of a Perforce repo into a git repo. The tree I've checked out has the following Perforce "branch" structure:
回购/发行版A
回购/发行版B
回购/功能A
回购/功能B
repo/releaseA
repo/releaseB
repo/featureA
repo/featureB
我在本地git仓库中到FeatureA目录的一堆git提交;但是,我想改为将这些提交重新设置"到featureB目录中.有没有办法将最初应用于一个目录的一组补丁/提交转换为另一个目录?
I have a bunch of git commits in my local git repo to the featureA directory; however, I'd like to "rebase" those commits onto the featureB directory instead. Is there a way to translate a set of patches/commits that were originally applied to one directory onto another instead?
推荐答案
是的.如果您的提交仅影响 repo/featureA
,这将非常简单:
Yep. If your commits affect only repo/featureA
this'll be very easy:
mkdir patches
git format-patch -o patches master..my_featureA_branch
git am patches/* -p3 --directory=repo/featureB
您完成了.
如果您提交的更改文件不在repo/featureA之内,则需要将其删除,
If your commits change files outside repo/featureA you need to strip those out,
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
之前.在这种情况下,git am --skip
中任何根本不影响任何补丁的补丁程序.
before the git am
. Any patches that didn't affect anything at all in repo/featureA
you'll have to git am --skip
in that case.
这篇关于将提交从一个子树提交到同一仓库中的另一个子树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!