【问题标题】:Apply patch to file that's under Git without using Git?在不使用 Git 的情况下将补丁应用于 Git 下的文件?
【发布时间】:2016-02-12 00:58:19
【问题描述】:

我从 Git 中查看了最新的 OpenSSL:

git clone git://git.openssl.org/openssl.git

其中一位开发者给我发了一个 AARCH64 的补丁来测试:

$ cat RT4237.diff 
diff --git a/crypto/ec/asm/ecp_nistz256-armv8.pl b/crypto/ec/asm/ecp_nistz256-armv8.pl
index 9d1bce1..ce6b69e 100644
--- a/crypto/ec/asm/ecp_nistz256-armv8.pl
+++ b/crypto/ec/asm/ecp_nistz256-armv8.pl
@@ -1289,6 +1289,9 @@ $code.=<<___;
    stp $acc0,$acc1,[$rp_real,#$i]
    stp $acc2,$acc3,[$rp_real,#$i+16]
 ___
+$code.=<<___   if ($i == 0);
+   adr $bp_real,.Lone_mont-64
+___
 }
 $code.=<<___;
    ldp $acc0,$acc1,[$ap_real,#$i]  // in1

补丁不适用于 Git。我不会分享 Git 的失败,所以人们不会因为解决 Git 问题而分心。相反,我只是想使用一个真正有效的工具。

我尝试使用 Apply Patch File to a Source Code Tree (patch -p3 &lt; RT4237.diff),但由于 Git 序言导致错误:

$ cd openssl
$ patch -p3 < RT4237.diff
(Stripping trailing CRs from patch; use --binary to disable.)
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/crypto/ec/asm/ecp_nistz256-armv8.pl b/crypto/ec/asm/ecp_nistz256-armv8.pl
|index 9d1bce1..ce6b69e 100644
|--- a/crypto/ec/asm/ecp_nistz256-armv8.pl
|+++ b/crypto/ec/asm/ecp_nistz256-armv8.pl
--------------------------

如何在不使用 Git 的情况下应用补丁


hikey:openssl$ pwd
/home/jwalton/openssl
hikey:openssl$ find . -name RT4237.diff 
./RT4237.diff
hikey:openssl$ find . -name ecp_nistz256-armv8.pl
./crypto/ec/asm/ecp_nistz256-armv8.pl

【问题讨论】:

  • 什么错误确切地?如果您检查了 correct 分支,并且 diff 对其有效,它应该 工作 [假设 -p 级别是正确的] 或给你一个列表它不能适用的帅哥。另外,“git序言”是什么意思?你的意思是第 1 行(即“差异”,因为补丁跳过它应该无关紧要)。或者,只需从 blah.diff 中删除第一行
  • @CraigEstey - “究竟是什么错误?” - 已添加错误消息。 “另外,“git preamble”是什么意思” - 序言是 diff --git ...。它显示在我收到的补丁的第一行。
  • 根据 Craig 关于 -p 的观点,patch 关于找不到要修补的文件的抱怨让我认为您的 cwd 与 -p3 不一致
  • 你能显示find . -name ecp_nistz256-armv8.pl吗?
  • 谢谢@Notlikethat。我花了大约 45 分钟试图让它发挥作用。在一个简单的任务上浪费了这么多时间之后,我决定转向一个在实践中有效的工具。

标签: git diff patch


【解决方案1】:

根据pwd 和补丁文件的内容,补丁需要使用-p1 标志来告诉补丁忽略路径名的前导“a/”部分,以便它找到文件修补:

$ cd openssl
$ patch -p1 < RT4237.diff 
(Stripping trailing CRs from patch; use --binary to disable.)
patching file crypto/ec/asm/ecp_nistz256-armv8.pl
$

【讨论】:

  • 值得一提...... -p0-p3 努力应用 git 补丁。这个答案肯定胜过 Git,它在手册页上花了我 45 分钟,Stack Overflow 和 U&L.SE 搜索如何让 Git 忽略它抱怨的空白。其经典的 Git 操作方式 - 将简单的任务变得困难。 (不,--ignore-whitespace 和朋友没有工作)。
【解决方案2】:

据我所知,git 补丁是带有序言的常规差异。 因此,删除 git preamble 并重试。

【讨论】:

    猜你喜欢
    • 2011-03-26
    • 2010-12-27
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 2020-08-13
    • 1970-01-01
    • 2013-07-21
    • 1970-01-01
    相关资源
    最近更新 更多