我在那里关注了很多文章,但我仍然不知道如何在Cygwin中使用diff和patch
这里我在Windows资源管理器中创建2个文件
origin.txt
one
two
three
Run Code Online (Sandbox Code Playgroud)
new.txt
one
four
five
Run Code Online (Sandbox Code Playgroud)
然后我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
Run Code Online (Sandbox Code Playgroud)
然后我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
Run Code Online (Sandbox Code Playgroud)
怎么克服这个?这与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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16858 次 |
| 最近记录: |