... Is there any easy way to tell which version the patch should be applied to?
Only if the patch contains an index
line. (Even then, it's not necessarily easy, and there may be many revisions to which the patch might apply.) In this case, that patch does have such a line:
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]
The index
line in a Git diff provides the old and new blob hash IDs. This means the version of CMakeLists.txt
to which the patch applies is a blob whose abbreviated hash ID is 91919ad
. If this hash ID is not uniquely some particular blob, one is in trouble; cloning the repository as it is today, I find:
$ git rev-parse 91919ad
91919adb4a289234062a27bed0276cb098d1e5d5
so we can use the answers from Which commit has this blob?
Rather than the fancy perl script, I went with VonC's answer:
$ git log --oneline --find-object=91919adb4a289234062a27bed0276cb098d1e5d5
e0597baed57 Remove Carve boolean
e8daf2e3ea1 CMake: cleanup
Note that we could use the abbreviated hash here since it's still unique:
$ git log --oneline --find-object=91919ad
e0597baed57 Remove Carve boolean
e8daf2e3ea1 CMake: cleanup
It's best to keep the full hash ID around, though, as eventually, the shortened hash may become non-unique and only a longer hash will serve. (The full hash will always work, as there's nothing longer than the full hash.)
Note that there are many commits "between" these two:
$ git rev-list --count e8daf2e3ea1..e0597baed57
752
All of those commits (except the last one) share that one version of 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]
This commit is the start of the 751 commits that contain that version of that file. Meanwhile:
$ 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
This is the first commit that stops using that version of extern/CMakeLists.txt
(after which no other master-branch version uses it).