2013-03-21 54 views
3

我跟很多的文章在那里,但我还是不知道如何使用diff和patch Cygwin中如何在Windows上使用Cygwin中的diff和补丁?

在这里,我在Windows资源管理器

origin.txt

one 
two 
three 
创建2个文件

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和64位Windows 7

回答

6

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

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

所以diff和补丁之前,我们做** ** DOS2UNIX的,那么在这之后,我们** ** unix2dos? – onmyway133 2013-03-21 13:05:23

+2

@entropy:是的。或者,理想情况下,坚持始终保持Unix格式。 – 2013-03-21 15:59:57