Assuming a patch was created from a specific commit in the past, and no longer applies to HEAD.
How can I find either the first or better the last commit in the history of HEAD, where this patch applies with "git apply" ? Maybe something with git bisect? But which command will tell me if a patch applies?
Ideally I want to move back to that commit, apply the patch, then rebase on or merge with the original HEAD, and diff again to create a new patch, unless there was a conflict. After this I would like to go back to the original HEAD, so I can continue with more patches.
Background: There is a number of patches that need to be rerolled... (and yes, there are ecosystems where patches are still a thing..)
This answer assumes that the patches were created with
git diff
, and notgit format-patch
, and that your default pager for yourgit log
isless
.Here is an example of a patch created from
git diff <sha1> <sha2>
,Take this line:
and search for it in
git log --patch
orgit log -p
. Type/
when inless
, then enter the regex you want to search for:The
+
is escaped with\
here, because it's a special character in regexes. Hit enter to find the first match, andn
to bring up the next match, orN
to go to the previous match.This will help you find commits that might be possible candidates for where the patch came from. You can also use spacebar in
less
to page down, andb
to page up.