如何在没有安装 git 的情况下应用 git diff --binary 补丁?

发布于 2024-08-15 08:37:22 字数 551 浏览 3 评论 0原文

我使用 git diff 生成可应用于远程服务器以更新项目的补丁。

在本地,我运行:

git diff --no-prefix HEAD~1 HEAD > example.patch

将 example.patch 上传到远程服务器并运行:

patch --dry-run -p0 < example.patch

如果 dry-run 成功,我运行:

patch -p0 < example.patch

这效果很好,除非 diff 包含二进制文件。今天发现可以使用:

git diff --no-prefix --binary HEAD~1 HEAD > example.patch

问题是生成的补丁文件无法使用patch应用。

在服务器没有安装 git 的情况下,如何应用这些二进制补丁文件?

我想保持使用空运行的能力。

谢谢

I use to git diff to generate patches that can be applied to remote server to update a project.

Locally, I run:

git diff --no-prefix HEAD~1 HEAD > example.patch

Upload example.patch to remote server and run:

patch --dry-run -p0 < example.patch

If dry-run is successful, I run:

patch -p0 < example.patch

This works well, except when diff includes binary files. Today, I found that I can use:

git diff --no-prefix --binary HEAD~1 HEAD > example.patch

The problem is that the generated patch file can not be applied using patch.

How can I apply these binary patch files without having git installed the server?

I would like to maintain ability to use dry-run.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

苏大泽ㄣ 2024-08-22 08:37:22

对于一个奇怪的答案,您可以使用 sshfs 将远程系统安装在您的任何位置确实有 git,然后以这种方式运行你的命令。从不同的参考框架解决问题:与其想知道如何在没有工具的地方运行命令,为什么不创建一个让数据到达您的工具的环境(通过 sshfs?)

For an outlandish answer, what you could do is use sshfs to mount the remote system upon where ever you do have git, and then run your commands that way. Approach the problem from a different frame of reference: Instead of wondering how to run commands where the tool is not, why not create an environment where the data comes to your tool ( via sshfs ? )

靖瑶 2024-08-22 08:37:22

在许多情况下,在这种情况下,您无法使用更高级的工具创建数据并使用不太先进的工具来使用它。 patch 适用于非二进制 git-diff,这是一个令人高兴的巧合。 git diff 引入了标准 diff 的扩展。

为了实现这个目标,你可以:

  • 在目标系统上安装 git (这确实是最好的方法)
  • 将目标系统挂载到本地,正如 chiggsy 所说的
  • scp/rsync new文件。对于小孩子来说还不错。

In many situations and in this too, you can't create data with more advanced tool and use it with less advanced. It's a happy coincidence that patch works for non-binary git-diffs. git diff introduces an extension to standard diff.

To achieve the goal, you can:

  • install git on the destination system (that's the best approach, really)
  • mount destination system to local, as chiggsy says
  • just scp/rsync new files. Not bad for small ones.
笔芯 2024-08-22 08:37:22

根据变更日志,我们预计补丁版本> 2.6.1 支持 GIT 二进制差异。

According to the change log, we can expect patch versions > 2.6.1 to support GIT binary diffs.

德意的啸 2024-08-22 08:37:22

使用这个

git apply example.patch
git add --patch
git commit

您可以省略 --patch 标志,但您不会看到每个更改并检查修补过程。

Use this

git apply example.patch
git add --patch
git commit

You can omit --patch flag, but you won't see every change and check patching process.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文