Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make and apply SVN patch?

Tags:

linux

diff

patch

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?

like image 856
Sandra Schlichting Avatar asked Apr 26 '12 12:04

Sandra Schlichting


People also ask

How do I create a patch in svn?

Creating a Patch File First you need to make and test your changes. Then instead of using TortoiseSVN → Commit... on the parent folder, you select TortoiseSVN → Create Patch... you can now select the files you want included in the patch, just as you would with a full commit.


2 Answers

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

like image 181
Fox Avatar answered Oct 16 '22 08:10

Fox


By default, patch ignores the directory portion of the target filename; it's just looking for "httpd.conf" in your current working directory. If you want it to use the full path, you have to explicitly ask it to do so with the -p option:

patch -p 0 < httpd.patch

The number after -p is how many levels to remove from the filename path; -p N strips off everything up to and including slash number N. The first slash is number 1, so -p 0 means "don't strip anything".

In general, you might be better off not relying on having the full path in the patch file, though; the patch will be more generally useful if it works even for files in a different directory layout. You can always cd into the directory containing the file before running patch (and use a full path to find the patch file itself, if needed, instead).

like image 52
Mark Reed Avatar answered Oct 16 '22 06:10

Mark Reed