从git仓库创建补丁或差异文件,并将其应用于另一个不同的git仓库 [英] Create patch or diff file from git repository and apply it to another different git repository

查看:384
本文介绍了从git仓库创建补丁或差异文件,并将其应用于另一个不同的git仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从事基于WordPress的项目,我想在WP的每个新发行版本中对我的项目进行补丁。为此,我想在两个提交或标记之间生成补丁。

I work on WordPress based project and I want to patch my project at each new release version of WP. For this, I want generate a patch between two commits or tags.

例如,在我的仓库 / www / WP 中,

For example, in my repo /www/WP I do this:

$ git patch-format com1..com2 --stdout > '~/patchs/mypatch.patch'

# or

$ git patch-format tag1..tag2 --stdout > '~/patchs/mypatch.patch'

/ www / WP git natif WordPress

/www/WP git natif WordPress

/ www / myproject 我的基于WordPress的git项目

/www/myproject My git project WordPress based

code> git apply 命令行不起作用,我认为是因为我们位于不同的存储库中。

The git apply command line doesn't work, I think because we are in different repositories.

是否可以生成不提交的补丁文件,只是一个差异并将其应用于另一个git存储库?

Can I generate a patch file without a commit, just a differential and apply it to another git repository?

谢谢。

推荐答案

您可以只使用 git diff 生成统一差异适用于 git apply

You can just use git diff to produce a unified diff suitable for git apply:

git diff tag1..tag2 > mypatch.patch

然后您可以通过以下方式应用生成的补丁:

You can then apply the resulting patch with:

git apply mypatch.patch

这篇关于从git仓库创建补丁或差异文件,并将其应用于另一个不同的git仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆