简体   繁体   English

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

[英]How to apply git diff --binary patches without git installed?

I use to git diff to generate patches that can be applied to remote server to update a project. 我使用git diff来生成可以应用于远程服务器以更新项目的补丁。

Locally, I run: 在本地,我跑:

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

Upload example.patch to remote server and run: 将example.patch上传到远程服务器并运行:

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. 这种方法很有效,除非diff包含二进制文件。 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? 如何在不安装git服务器的情况下应用这些二进制补丁文件?

I would like to maintain ability to use dry-run. 我想保持使用干跑的能力。

Thank you 谢谢

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. 对于一个古怪的答案,你可以做的是使用sshfs将远程系统挂载到你拥有git的地方,然后以这种方式运行你的命令。 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 ? ) 从不同的参考框架中解决问题:为什么不创建一个数据来到工具的环境(通过sshfs?),而不是想知道如何运行工具不在哪里的命令。

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. 这个patch适用于非二进制git-diffs,这是一个令人高兴的巧合。 git diff introduces an extension to standard diff. git diff引入了标准差异的扩展。

To achieve the goal, you can: 要实现这一目标,您可以:

  • install git on the destination system (that's the best approach, really) 在目标系统上安装git(这是最好的方法,真的)
  • mount destination system to local, as chiggsy says chiggsy说,将目的地系统挂载到本地
  • just scp / rsync new files. 只是scp / rsync新文件。 Not bad for small ones. 小的也不错。

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

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. 您可以省略--patch标志,但不会看到每个更改并检查修补过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM