如何制作和应用SVN补丁? [英] How to make and apply SVN patch?

查看:261
本文介绍了如何制作和应用SVN补丁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为httpd.conf创建一个SVN类型的补丁文件,以便可以轻松地将其应用于其他主机.

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

如果我愿意

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

我得到:

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: 

问题

我在做什么错了?

推荐答案

默认情况下,patch忽略目标文件名的目录部分;它只是在当前工作目录中寻找"httpd.conf".如果希望它使用完整路径,则必须使用-p选项明确要求它使用它:

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

-p之后的数字是从文件名路径中删除多少个级别; -p N剥离所有不包括斜杠号N的内容.第一个斜杠为数字1,因此-p 0的意思是不要剥离任何东西".

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".

通常,最好不要依赖修补程序文件中的完整路径.如果该修补程序甚至适用于其他目录布局中的文件,该修补程序也将更为有用.运行修补程序之前,您始终可以cd进入包含文件的目录(如果需要,可以使用完整路径查找修补程序文件本身).

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).

这篇关于如何制作和应用SVN补丁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆