【问题标题】:How to use diff and patch in Cygwin on Windows?如何在 Windows 上的 Cygwin 中使用差异和补丁?
【发布时间】:2013-03-10 16:45:42
【问题描述】:

我关注了很多文章,但我仍然不知道如何在 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 64bit

【问题讨论】:

  • 如果您没有安装patch,请使用:apt-cyg install patch。 (在它自己的包中称为patch。)

标签: cygwin diff patch


【解决方案1】:

这几乎肯定是一个行尾问题。您可以通过首先在文件上运行 dos2unix 来解决此问题:

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

【讨论】:

  • 所以在 diff 和 patch 之前,我们执行 dos2unix,然后,我们执行 unix2dos ?
  • @entropy:是的。或者,理想情况下,始终坚持使用 Unix 格式。
猜你喜欢
  • 2010-10-05
  • 1970-01-01
  • 1970-01-01
  • 2011-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多