Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using diff/patch in windows, aka, "can't find file to patch at input line 4"

I am using CVS and win7. I need to copy some changes from the trunk to a branch, so I thought I could just use "diff -ruN" to put the changes into a file, and then use "patch -i" to apply them to the branch.

So I saw this page, and this page. I already had cygwin diff, so I got gnu patch here. I made two files

\test\mydir1\afile.txt
\test\mydir2\afile.txt

which have minor differences. Then I type

cd test
diff -ruN mydir1 mydir2 >test.patch
patch --dry-run -i test.patch

and the result is

can't find file to patch at input line 4
Perhaps you should have used the -p or --strip option?

so I tried

patch --dry-run --verbose -p1 -i test.patch

and I get the same error. I tried a lot of other things for a long time with no success. Why is this so hard?

like image 640
John Henckel Avatar asked Mar 01 '13 14:03

John Henckel


1 Answers

Ok here are the two things I needed to know, but were not documented anywhere

  • diff output uses unix format, but patch requires dos format
  • the default "strip" in patch is NOT -p0 like you might expect. It is -p1.

This works...

diff -ruN mydir1 mydir2 | unix2dos > test.patch
patch -p0 -i test.patch

You must convert to DOS line endings, and you must specify -p0. Otherwise the default is -p1. I hope this will help someone else.

like image 140
John Henckel Avatar answered Nov 15 '22 03:11

John Henckel