我有一个带有我希望使用的绝对路径的补丁。即前几行如下。
--- /usr/share/apps/plasma/packages/org.kde.pager/contents/ui/main.qml 2014-10-10 18:47:23.000000000 +1100
+++ /usr/share/apps/plasma/packages/org.kde.pager/contents/ui/main.qml.mod 2014-11-11 09:44:17.786200477 +1100
但是,除非我位于根目录中,否则它会失败。
~$ cd
~$ sudo patch -i /tmp/fix_kde_icons.patch -p0
Ignoring potentially dangerous file name /usr/share/apps/plasma/packages/org.kde.pager/contents/ui/main.qml
Ignoring potentially dangerous file name /usr/share/apps/plasma/packages/org.kde.pager/contents/ui/main.qml.mod
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
...
~$ cd /tmp
/tmp$ sudo patch -i /tmp/fix_kde_icons.patch -p0
... #same error as above
/tmp$ cd /usr
/usr$ sudo patch -i /tmp/fix_kde_icons.patch -p0
... #same error as above
/usr$ cd /
/$ sudo patch -i /tmp/fix_kde_icons.patch -p0
patching file /usr/share/apps/plasma/packages/org.kde.pager/contents/ui/main.qml
有没有办法patch
在任何工作目录中使用绝对路径?
答案1
查看GNU补丁的源代码,这个行为是从2.7版本开始内置的。从 GNU patch 2.7.1 开始,仅..
接受不包含的相对路径,除非当前目录是根目录。
要应用包含绝对路径的补丁,您可以使用
(cd / && sudo patch -p0) <foo.patch
在最新版本的 GNU 补丁中,您可以简单地
sudo patch -d/ -p0 <foo.patch
答案2
至少使用 GNU 补丁 2.7.6,可以指定文件名:
patch /usr/share/apps/plasma/packages/org.kde.pager/contents/ui/main.qml /tmp/fix_kde_icons.patch