Linux 如何制作和应用SVN补丁?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10333712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make and apply SVN patch?
提问by Sandra Schlichting
I would like to make a SVN type patch file for httpd.conf
so I can easily apply it to other hosts.
我想制作一个 SVN 类型的补丁文件,httpd.conf
以便我可以轻松地将其应用于其他主机。
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?
我究竟做错了什么?
采纳答案by Mark Reed
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
忽略目标文件名的目录部分;它只是在您当前的工作目录中寻找“httpd.conf”。如果您希望它使用完整路径,则必须使用以下-p
选项明确要求它这样做:
patch -p 0 < httpd.patch
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".
后面的数字-p
是从文件名路径中删除多少级;-p N
去除包括斜线编号 N 在内的所有内容。第一个斜线是编号 1,因此-p 0
表示“不要去除任何东西”。
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).
不过,一般来说,最好不要依赖补丁文件中的完整路径;如果补丁甚至适用于不同目录布局中的文件,它将会更普遍有用。在运行补丁之前,您始终可以 cd 进入包含该文件的目录(如果需要,可以使用完整路径来查找补丁文件本身)。
回答by Fox
Use svn patch
.
使用svn patch
.
Case 1: using /usr/bin/patch
:
案例1:使用/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
如果没有通过svn add
或svn delete
Case 2: using svn patch
:
案例2:使用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 move
s and rename
s
请注意,既不跟踪svn move
s 和rename
s
回答by James Wierzba
If you're using TortoiseSVN there is a easy to use interface to create and apply a patch.
如果您使用 TortoiseSVN,则有一个易于使用的界面来创建和应用补丁。
To create:
创造:
Right click on folder -> TortoiseSVN -> Create patch
右键单击文件夹 -> TortoiseSVN -> 创建补丁
You will be prompted to select an output file
系统将提示您选择一个输出文件
To apply:
申请:
Right click on folder -> TortoiseSVN -> Apply patch
右键单击文件夹 -> TortoiseSVN -> 应用补丁
You will be prompted with an interface to select the file(s) to apply the patches to, and merge if necassary.
系统将提示您选择要应用补丁的文件,并在必要时合并。