如何在 Windows 上打补丁?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19611/
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 patch on Windows?
提问by Ashwin Nanjappa
Given a (source) patch file, what's the easiest way to apply this patch on the source files under Windows?
给定一个(源)补丁文件,在 Windows 下将这个补丁应用到源文件上的最简单方法是什么?
A GUI tool where I can visually compare the unchanged-changed source lines would be great.
一个 GUI 工具,我可以在其中直观地比较未更改的源代码行会很棒。
采纳答案by SCdF
Patch for Windowsis what you're looking for.
适用于 Windows 的补丁正是您要找的。
回答by Nicolas Thery
Thanks to Macke, a good way to apply a patch file under Windows OS is using Git. As I understood, Git is a version control solution like SVN.
感谢 Macke,在 Windows 操作系统下应用补丁文件的一个好方法是使用 Git。据我了解,Git 是一种类似于 SVN 的版本控制解决方案。
Here is a guideline to apply a patch :
以下是应用补丁的指南:
- First of all, download the latest release of the Windows Git Edition here : GIT
- With the cmd prompt, change directory to the patch file and files to patch
- Now you can use the following command line :
- 首先,在这里下载最新版本的 Windows Git 版: GIT
- 在 cmd 提示符下,将目录更改为补丁文件和要补丁的文件
- 现在您可以使用以下命令行:
git apply --ignore-space-change --ignore-whitespace --whitespace=nowarn file.patch
git apply --ignore-space-change --ignore-whitespace --whitespace=nowarn file.patch
Simple isn't it ?
是不是很简单?
Thank you Macke
谢谢马克
回答by VonC
Not that since Git 2.3.3 (March 2015), you can use git apply --unsafe-paths
to use git apply outside a git repo.
不是因为 Git 2.3.3(2015 年 3 月),您可以git apply --unsafe-paths
使用 git apply 在 git repo 之外使用。
See commit 5244a31by Junio C Hamano (gitster
)
"git apply
" was not very careful about reading from, removing, updating and creating paths outside the working tree (under --index
/--cached
) or the current directory (when used as a replacement for GNU patch).
" git apply
" 在读取、删除、更新和创建工作树(在--index
/下--cached
)或当前目录(当用作 GNU 补丁的替代品)之外的路径时不是很小心。
The documentation now includes:
该文档现在包括:
--unsafe-paths:
By default, a patch that affects outside the working area (either a Git controlled working tree, or the current working directory when "
git apply
" is used as a replacement of GNU patch) is rejected as a mistake (or a mischief).When
git apply
is used as a "better GNU patch", the user can pass the--unsafe-paths
option to override this safety check.
This option has no effect when--index
or--cached
is in use.
默认情况下,影响工作区域之外的补丁(Git 控制的工作树,或者当“
git apply
”用作 GNU 补丁的替换时的当前工作目录)作为错误(或恶作剧)被拒绝。当
git apply
用作“更好的 GNU 补丁”时,用户可以通过--unsafe-paths
选项来覆盖此安全检查。
此选项在使用--index
或--cached
正在使用时无效。
So if you have git installed, git apply
could help, even outside of any git repo.
因此,如果您安装了gitgit apply
,即使在任何 git repo 之外,也可以提供帮助。