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 ?
Is it possible that some of the files have Windows (DOS) line endings instead of Unix newlines? Try running
dos2unix
on them before doing thediff
.Both
dos2unix
andfromdos
(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 usefind
to process them.Then when you're satisfied that all went well:
to delete the backups.
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?