2

I have some files in my server that I wanted to make a patch for, so I took one of the files to test:

cp /path/file ~/file

So now I have just the same file in my root directory so I make any changes I need on the file at ~/file and now I run the diff command on the 2 files:

diff -Nuar /path/file ~/file > my_file.patch

I have also tried:

diff -u /path/file ~/file > my_file.patch
diff -c /path/file ~/file > my_file.patch
diff /path/file ~/file > my_file.patch

Now as you can see there is no differences on the files besides what I have just changed on it but instead of creating a my_file.patch with only the code to patch the changes I made into /path/file it always create a full file with all the content of /path/file marked to be removed and the content of ~/file marked to be added.

Then I try to apply the patch:

patch -p0 < ~/my_file.patch

And it fails badly ... it always print out a reject file with all the content just like the file is.

I am running out of ideas to why it is doing this all the time, with a few files I can produce a patch without problems but with most of the files on the system that I need to make one it won't work at all.

Any ideas on what could be the problem ? encoding, format ? solutions ?

Prix
  • 4,881
  • 3
  • 24
  • 25
  • Is it possible that some of the files have Windows (DOS) line endings instead of Unix newlines? Try running `dos2unix` on them before doing the `diff`. – Dennis Williamson Nov 01 '10 at 15:52
  • You might also cut and paste the first few header lines of the patch file here, minus the actual data for us to look at. – mfarver Nov 01 '10 at 16:01
  • @Dennis Williamson indeed the files seemed to be in dos format so on the linux i had to run fromdos < /path/file > /path/file.unix inst there a better way to accomplish this ? I dont want to have to do this with all the 10k files and then rename it all back. – Prix Nov 01 '10 at 16:12
  • I will post my suggestion as an answer along with an answer to the question in your comment. – Dennis Williamson Nov 01 '10 at 17:49

2 Answers2

2

Is it possible that some of the files have Windows (DOS) line endings instead of Unix newlines? Try running dos2unix on them before doing the diff.

Both dos2unix and fromdos (on my system, the former is a symlink to the latter) accept filenames on the command line and do the conversion in place. You can use the -b option to have it make a backup. If you have a lot of these files in various directories, you can use find to process them.

find /dir/to/start -type f -name "foo*" -exec fromdos -b {} +

Then when you're satisfied that all went well:

find /dir/to/start -type f -name "foo*.bak"  -delete

to delete the backups.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
0

patch is very sensitive to its current directory and to the -p option. Are you certain that you are attempting to apply the patch from the correct location? Are you specifying a prefix (via -p) that is appropriate to the contents of your patch file?

Steven Monday
  • 13,599
  • 4
  • 36
  • 45
  • yes I am sure it is an issue with the files itself like Dennis spotted on the comments, I have also created files to test it to make sure just in case. – Prix Nov 01 '10 at 16:28