如何在没有安装 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
How to apply `git diff` patch without Git installed?
提问by Andrey Kuznetsov
How can my client apply patch created by git diff
without git installed?
I have tried to use patch
command 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 patchfile
if you need handle file adds, deletes and renames.
工作,但正如许多人在评论和其他答案中注意到的那样,补丁不理解添加、删除和重命名。没有选项,但git apply patchfile
如果您需要处理文件添加、删除和重命名。
EDITDecember 2015
编辑2015 年 12 月
Latest versions of patch
command (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 patch
there is no need to use git
to 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 apply
also handles file adds, deletes, and renames if they're described in the git diff
format, which patch
won't do. Finally, git apply
is 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