如何在Windows上使用diff和patch Cygwin? [英] How to use diff and patch in Cygwin on Windows?

查看:890
本文介绍了如何在Windows上使用diff和patch Cygwin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在许多文章,但仍然不知道如何使用diff和补丁在Cygwin

I follow many articles out there but I still don't know how to use diff and patch in Cygwin

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

Here I create 2 files in Windows Explorer

origin.txt

one
two
three

new.txt

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文件格式相关吗?

How to overcome this? Is this related to Unix and Windows file format?

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

P/S: I'm using CYGWIN_NT-6.1-WOW64 and Windows 7 64bit

推荐答案

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

This is almost certainly a line-ending problem. You can fix this by running dos2unix over the files first:

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

这篇关于如何在Windows上使用diff和patch Cygwin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆