git apply --check file.patch ingores first `/`
git apply --check file.patch ingores first `/`
我正在尝试将自己创建的补丁应用于项目。
所以我做了以下命令:
diff -ru src /mnt/windows/Programming/pull_requests/himalaya/src > file.patch
现在这些是 file.patch
中的第一行:
diff --color -ru src/config/tui/tui.rs /mnt/windows/Programming/pull_requests/himalaya/src/config/tui/tui.rs
--- src/config/tui/tui.rs 2021-06-07 20:50:19.398724000 +0200
+++ /mnt/windows/Programming/pull_requests/himalaya/src/config/tui/tui.rs 2021-07-07 10:06:40.787428476 +0200
现在如果我 git apply --check file.patch
,我会得到这个:
error: mnt/windows/Programming/pull_requests/himalaya/src/config/tui/tui.rs: No such file or directory
如您所见,/mnt
缺少第一个 /
。为什么呢?为什么不正确?这个补丁看起来很适合我。
提示
我在linux,windows
只是一个目录名
如果您真的想要git检查描述将您的存储库文件移动到存储库之外的路径的内容,请尝试--unsafe-paths
option,并且添加 -p 0
以保留前导斜杠。
恕我直言:如果您的目的只是检查补丁是否可以正确应用到您的本地 src/config/tui/tui.rs
文件,您最好手动编辑补丁,从第 3 行删除绝对前缀:
+++ src/config/tui/tui.rs 2021-07-07 10:06:40.787428476 +0200
--unsafe-paths
选项的文档说明了您的补丁被拒绝的原因:
--unsafe-paths
By default, a patch that affects outside the working area (either a Git controlled working tree, or the current working directory when "git apply" is used as a replacement of GNU patch) is rejected as a mistake (or a mischief).
When git apply
is used as a "better GNU patch", the user can pass the --unsafe-paths
option to override this safety check. This option has no effect when --index
or --cached
is in use.
我正在尝试将自己创建的补丁应用于项目。 所以我做了以下命令:
diff -ru src /mnt/windows/Programming/pull_requests/himalaya/src > file.patch
现在这些是 file.patch
中的第一行:
diff --color -ru src/config/tui/tui.rs /mnt/windows/Programming/pull_requests/himalaya/src/config/tui/tui.rs
--- src/config/tui/tui.rs 2021-06-07 20:50:19.398724000 +0200
+++ /mnt/windows/Programming/pull_requests/himalaya/src/config/tui/tui.rs 2021-07-07 10:06:40.787428476 +0200
现在如果我 git apply --check file.patch
,我会得到这个:
error: mnt/windows/Programming/pull_requests/himalaya/src/config/tui/tui.rs: No such file or directory
如您所见,/mnt
缺少第一个 /
。为什么呢?为什么不正确?这个补丁看起来很适合我。
提示
我在linux,windows
只是一个目录名
如果您真的想要git检查描述将您的存储库文件移动到存储库之外的路径的内容,请尝试--unsafe-paths
option,并且添加 -p 0
以保留前导斜杠。
恕我直言:如果您的目的只是检查补丁是否可以正确应用到您的本地 src/config/tui/tui.rs
文件,您最好手动编辑补丁,从第 3 行删除绝对前缀:
+++ src/config/tui/tui.rs 2021-07-07 10:06:40.787428476 +0200
--unsafe-paths
选项的文档说明了您的补丁被拒绝的原因:
--unsafe-paths
By default, a patch that affects outside the working area (either a Git controlled working tree, or the current working directory when "git apply" is used as a replacement of GNU patch) is rejected as a mistake (or a mischief).
When
git apply
is used as a "better GNU patch", the user can pass the--unsafe-paths
option to override this safety check. This option has no effect when--index
or--cached
is in use.