如何在没有安装 git 的情况下应用 git diff --binary 补丁?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1910615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to apply git diff --binary patches without git installed?
提问by Taras Mankovski
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. Today, I found that I can use:
这很有效,除非 diff 包含二进制文件。今天,我发现我可以使用:
git diff --no-prefix --binary HEAD~1 HEAD > example.patch
The problem is that the generated patch file can not be applied using patch.
问题是生成的补丁文件不能用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
谢谢
采纳答案by chiggsy
For an outlandish answer, what you could do is use sshfsto 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 ? )
对于一个古怪的答案,您可以做的是使用sshfs将远程系统挂载到您拥有 git 的任何地方,然后以这种方式运行您的命令。从不同的参考框架解决问题:与其想知道如何在没有工具的地方运行命令,为什么不创建一个环境让数据进入您的工具(通过 sshfs ?)
回答by temoto
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.
在许多情况下,在这种情况下,您无法使用更高级的工具创建数据并使用不太先进的工具来使用它。这是一个patch
适用于非二进制 git-diff的快乐巧合。git 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.
- 在目标系统上安装 git(这是最好的方法,真的)
- 将目标系统挂载到本地,正如 chiggsy 所说
- 只是
scp
/rsync
新文件。对小孩子来说还不错。
回答by Raphael Bossek
According to the change log, we can expect patch versions > 2.6.1 to support GIT binary diffs.
根据更改日志,我们可以预期补丁版本> 2.6.1 以支持 GIT 二进制差异。
回答by Zebooka
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 标志,但您不会看到每个更改并检查修补过程。