我关注了很多文章,但我仍然不知道如何在 Cygwin 中使用差异和补丁

在这里,我在 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 中使用差异和补丁?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15543046/

10-13 08:11
查看更多