[英]Using git diff to replicate changes in another directory
I have multiple websites structured (simplified) as follows under a single GIT repository:我在一个 GIT 存储库下有多个网站结构(简化)如下:
/
/site-1
/site-1/index.js
/site-1/about.js
/site-1/package.json
/site-1/node_modules(not versioned)
/site-1/package-lock.json(not versioned)
/site-2
/site-2/index.js
/site-2/about.js
/site-2/package.json
/site-2/node_modules(not versioned)
/site-2/package-lock.json(not versioned)
/site-3
/site-3/index.js
/site-3/about.js
/site-3/package.json
/site-3/node_modules(not versioned)
/site-3/package-lock.json(not versioned)
I did some amendments in /site-1/index.js , /site-1/package.json and added a file /site-1/changes.md .我在/site-1/index.js 、 /site-1/package.json中做了一些修改,并添加了一个文件/site-1/changes.md 。 The changes were done in 2 separate git commit in a feature branch called feature/carousel .
更改是在名为feature/carousel的功能分支中的 2 个单独的 git 提交中完成的。
I want to apply the same changes in /site-2 and /site-3 .我想在/site-2和/site-3中应用相同的更改。
I've tried the following:我尝试了以下方法:
git format-patch master -o patches
to retrieve the new diff in this feature branch with regards to master branch, but i was unable to apply the diff in /site-2 and /site-3 . git format-patch master -o patches
来检索此功能分支中关于master分支的新差异,但我无法在/site-2和/site-3中应用差异。diff -ruN site-1 site-2 > PatchFile1
to generate a consolidated diff, but it takes into account files that have been modified in /site-2 as well and its not a generic diff that can be applied directly to /site-3 diff -ruN site-1 site-2 > PatchFile1
生成一个合并的差异,但它也考虑了在/site-2中修改过的文件,它不是可以直接应用于/site-3的通用差异Any idea how to achieve this?知道如何实现这一目标吗?
You can use git apply
with the --directory
option to apply a patch to another main directory, as explained here:您可以使用
git apply
和--directory
选项将补丁应用到另一个主目录,如下所述:
https://blog.soltysiak.it/en/2017/08/how-to-use-git-patch-system-to-apply-changes-into-another-folder-structure/ https://blog.soltysiak.it/en/2017/08/how-to-use-git-patch-system-to-apply-changes-into-another-folder-structure/
First, create a patch file changes.patch
based on the changes applied to directory site-1
.首先,根据应用于目录
site-1
的更改创建补丁文件changes.patch
。 Then you can do the following:然后您可以执行以下操作:
git apply -p1 --directory='site-2' changes.patch
git apply -p1 --directory='site-3' changes.patch
-p1
removes the site folder from the patch headers, which is the main part that differs between the different directories. -p1
从补丁头中删除站点文件夹,这是不同目录之间不同的主要部分。
--directory='site-2'
will cause the site-2
prefix to be added to each header in the patch --directory='site-2'
将导致site-2
前缀添加到补丁中的每个header
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.