Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 ?

share|improve this question
    
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 1 '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 1 '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 1 '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 1 '10 at 17:49

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
sounds like a plan thanks, is there a way to define a default output folder for -b as well ? –  Prix Nov 1 '10 at 21:32
    
@Prix: The backup files will be output in the same directory where the file is. –  Dennis Williamson Nov 2 '10 at 1:02

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?

share|improve this answer
    
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 1 '10 at 16:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.