[英]Merge a Git commit into another repository with different directory
We have two Git repositories "installer" and "software" with both containing an Apache Tomcat server:我们有两个 Git 存储库“安装程序”和“软件”,两者都包含一个 Apache Tomcat 服务器:
installer/common/tomcat
software/dist/tomcat
I update Tomcat in "installer" and commit the changes.我在“安装程序”中更新 Tomcat 并提交更改。
When we used SVN I just used to do an svn merge --accept=tf src@rev1 src@rev2 .
当我们使用 SVN 时,我只是用来做一个svn merge --accept=tf src@rev1 src@rev2 .
where src
is the URL of the "installer" repo including common/tomcat
path and rev1
and rev2
are the revision just before and after the update.其中src
是“安装程序”回购包括的URL common/tomcat
路径和rev1
和rev2
是修订之前和更新之后。 The .
.
is the dist/tomcat
directory from "software".是来自“软件”的dist/tomcat
目录。
The changes affect mostly text files and *.jar files.这些更改主要影响文本文件和 *.jar 文件。
I've been trying all day long to do the equivalent with Git and so far I think, creating a patch from "installer" about that single commit and applying it to "software" is the appropriate way, eg我一整天都在尝试用 Git 做等效的事情,到目前为止我认为,从“安装程序”创建一个关于该单个提交的补丁并将其应用于“软件”是合适的方法,例如
/installer$ git format-patch --binary -1 <commit>
/software$ git am -p2 --directory='dist' <patch file>
I use -p2 to strip leading directories (which is 'a/common') and add the proper target directory from "software".我使用 -p2 去除前导目录(即“a/common”)并从“软件”中添加正确的目标目录。 I tried with "git diff" and "git apply" but only with varying error messages.我尝试了“git diff”和“git apply”,但只有不同的错误消息。 Sometimes there are issues with text files and changes are not applied.有时文本文件存在问题并且未应用更改。 Sometimes Git complains about the JAR files:有时 Git 会抱怨 JAR 文件:
error: patch not applied to <file> which does not match the current contents
How can I achieve this and make Git stop complaining and just apply the patch?我怎样才能做到这一点并让 Git 停止抱怨并应用补丁? Isn't there a parameter like --accept=tf
like in SVN? SVN中没有像--accept=tf
这样的参数吗?
One way to carry it out is through using a different branch, say tomcat
, created from installer
.实现它的一种方法是使用不同的分支,比如从installer
创建的tomcat
。 In tomcat
rename common/tomcat
to dist/tomcat
there.在tomcat
将common/tomcat
tomcat
重命名为dist/tomcat
。 When you want to bring over a change from installer
to software
, you first cherry-pick it into tomcat
(git should be able to see the renamed files and adjust paths accordingly) and then you can create the patch from there which should work fine in software
.当您想将installer
更改为software
,您首先将其挑选到tomcat
(git 应该能够看到重命名的文件并相应地调整路径),然后您可以从那里创建补丁,它应该可以正常工作software
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.