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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3418277/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:51:41  来源:igfitidea点击:

How to apply `git diff` patch without Git installed?

gitdiffpatch

提问by Andrey Kuznetsov

How can my client apply patch created by git diffwithout git installed? I have tried to use patchcommand but it always asks file name to patch.

我的客户端如何应用git diff未安装 git创建的补丁?我曾尝试使用patch命令,但它总是要求修补文件名。

回答by Andrey Kuznetsov

git diff > patchfile

and

patch -p1 < patchfile

work but as many people noticed in comments and other answers patch does not understand adds, deletes and renames. There is no option but git apply patchfileif you need handle file adds, deletes and renames.

工作,但正如许多人在评论和其他答案中注意到的那样,补丁不理解添加、删除和重命名。没有选项,但git apply patchfile如果您需要处理文件添加、删除和重命名。



EDITDecember 2015

编辑2015 年 12 月

Latest versions of patchcommand (2.7, released in September 2012) support most features of the "diff --git" format, including renames and copies, permission changes, and symlink diffs(but not yet binary diffs) (release announcement).

patch命令的最新版本(2.7,2012年 9 月发布)支持“diff --git”格式的大多数功能,包括重命名和复制、权限更改和符号链接差异(但不是二进制差异)(发布公告)。

So provided one uses current/latest version of patchthere is no need to use gitto be able to apply its diff as a patch.

因此,只要使用当前/最新版本,patch就无需使用git能够将其差异作为补丁应用。

回答by suppie

try this:

尝试这个:

patch -p1 < patchfile

回答by Sola Yang

Use

git apply patchfile

if possible.

如果可能的话。

patch -p1 < patchfile 

has potential side-effect.

有潜在的副作用。

git applyalso handles file adds, deletes, and renames if they're described in the git diffformat, which patchwon't do. Finally, git applyis an "apply all or abort all" model where either everything is applied or nothing is, whereas patch can partially apply patch files, leaving your working directory in a weird state.

git apply还处理文件添加、删除和重命名,如果它们以git diff格式描述,patch则不会这样做。最后,git apply是“全部应用或全部中止”模型,其中要么应用所有内容,要么不应用任何内容,而补丁可以部分应用补丁文件,使您的工作目录处于奇怪的状态。

回答by denis.peplin

I use

我用

patch -p1 --merge < patchfile

This way, conflicts may be resolved as usual.

这样,冲突可以照常解决。

回答by Shashi

Try this:

尝试这个:

$ git apply file.diff