How to make and apply SVN patch?

Sandra Schlichting picture Sandra Schlichting · Apr 26, 2012 · Viewed 83.6k times · Source

I would like to make a SVN type patch file for httpd.conf so I can easily apply it to other hosts.

If I do

cd /root
diff -Naur /etc/httpd/conf/httpd.conf_original /etc/httpd/conf/httpd.conf > httpd.patch
cp /etc/httpd/conf/httpd.conf_original /etc/httpd/conf/httpd.conf
patch < httpd.patch

I get:

can't find file to patch at input line 3
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|--- /etc/httpd/conf/httpd.conf_original    2012-04-26 13:36:08.331068438 +0200
|+++ /etc/httpd/conf/httpd.conf 2012-04-26 14:27:36.857075085 +0200
--------------------------
File to patch: 

Question

What am I doing wrong?

Answer

Fox picture Fox · Jul 16, 2013

Use svn patch.

Case 1: using /usr/bin/patch:

svn diff > $TMPDIR/mypatchfile.patch
cd myOtherCheckOut
patch -p0 < $TMPDIR/mypatchfile.patch

Applies your changes well if there are no added/deleted files through svn add or svn delete

Case 2: using svn patch:

svn diff > $TMPDIR/mypatchfile.patch
cd myOtherCheckOut
svn patch $TMPDIR/mypatchfile.patch

Tracks added and deleted files too.

Note that neither tracks svn moves and renames