... 有什么简单的方法可以判断补丁应该应用到哪个版本?
仅当补丁包含index 行时。 (即便如此,它也不一定容易,并且可能有许多修订版可能适用补丁。)在这种情况下,that patch 确实有这样一行:
diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt
index 91919ad..fed9e0c 100644
--- a/extern/CMakeLists.txt
+++ b/extern/CMakeLists.txt
@@ -37,6 +37,7 @@ if(CMAKE_COMPILER_IS_GNUCC)
[snip]
Git diff 中的 index 行提供旧的和新的 blob 哈希 ID。这意味着补丁应用的CMakeLists.txt 版本是一个blob,其哈希ID 缩写为91919ad。如果这个哈希 ID 不是唯一的某个特定 blob,那么就有麻烦了;像今天一样克隆存储库,我发现:
$ git rev-parse 91919ad
91919adb4a289234062a27bed0276cb098d1e5d5
所以我们可以使用Which commit has this blob?的答案
我选择了 VonC 的答案,而不是花哨的 perl 脚本:
$ git log --oneline --find-object=91919adb4a289234062a27bed0276cb098d1e5d5
e0597baed57 Remove Carve boolean
e8daf2e3ea1 CMake: cleanup
请注意,我们可以在这里使用缩写哈希,因为它仍然是唯一的:
$ git log --oneline --find-object=91919ad
e0597baed57 Remove Carve boolean
e8daf2e3ea1 CMake: cleanup
最好保留完整的散列 ID,但最终,缩短的散列可能会变得不唯一,只有更长的散列才会提供服务。 (完整的散列将始终有效,因为没有什么比完整的散列更长。)
请注意,这两个“之间”有很多提交:
$ git rev-list --count e8daf2e3ea1..e0597baed57
752
所有这些提交(最后一个除外)分享extern/CMakeLists.txt的一个版本:
$ git show e8daf2e3ea1 -- extern/CMakeLists.txt
commit e8daf2e3ea17c2e9569e6fc9b49879c74d9a8c22
Author: Campbell Barton [snip]
diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt
index f7e98525b8b..91919adb4a2 100644
--- a/extern/CMakeLists.txt
+++ b/extern/CMakeLists.txt
[snip]
此提交是包含该文件版本的 751 个提交的开始。同时:
$ git show e0597baed57 -- extern/CMakeLists.txt
commit e0597baed57fa7a9dfaf6dff6d0fa120784d21ea
Author: Sergey Sharybin [snip]
diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt
index 91919adb4a2..2e8589ffd17 100644
--- a/extern/CMakeLists.txt
+++ b/extern/CMakeLists.txt
这是使用该版本的extern/CMakeLists.txt 的第一个停止提交(之后没有其他主分支版本使用它)。