gpt4 book ai didi

cygwin - 如何在 Windows 上的 Cygwin 中使用 diff 和 patch?

转载 作者:行者123 更新时间:2023-12-03 03:25:48 25 4
gpt4 key购买 nike

我关注了很多文章,但我仍然不知道如何在 Cygwin 中使用 diff 和 patch

这里我在Windows资源管理器中创建了2个文件

origin.txt

one
two
three

new.txt

one
four
five

然后我diff -u origin.txt new.txt > file.patch结果是这样的

--- origin.txt  2013-03-21 15:53:20.062956800 +0700
+++ new.txt 2013-03-21 15:53:29.191869600 +0700
@@ -1,3 +1,3 @@
one
-two
-three
\ No newline at end of file
+four
+five
\ No newline at end of file

然后我patch origin.txt < file.patch显示错误

patching file origin.txt
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file origin.txt.rej

如何克服这个问题?这与 Unix 和 Windows 文件格式有关吗?

P/S:我使用的是 CYGWIN_NT-6.1-WOW64 和 Windows 7 64 位

最佳答案

这几乎肯定是一个行结束问题。您可以通过首先对文件运行 dos2unix 来修复此问题:

$ dos2unix origin.txt new.txt
$ patch origin.txt < file.patch
patching file origin.txt

关于cygwin - 如何在 Windows 上的 Cygwin 中使用 diff 和 patch?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15543046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com