Assume the following git
branch: A -> B -> C -> D -> E -> F -> G
I've determined via git bisect
that commit C introduced a bug, but reverting the changes introduced by C at the top of the branch does not solve the issue. This indicated to me that there are other bugs in later commits on that branch.
Is there a way to synthesize the following branch: A -> B -> D1 -> E1 -> F1 -> G1 , where the 1 indicates that the changes introduced in commit C do not exist ? I would then run git bisect
on that branch as well to determine find the other bug. [ hopefully this would not need to be repeated multiple times ]
Yes:
git checkout -b newbranch <specifier-for-B>
git cherry-pick <specifier-for-C>..<specifier-for-G>
These <specifier>
s can be raw hash IDs, or branch names, or branch names with ~number
to count back number
first-commits, and so on. The trick is to make a new branch that ends at the last good commit, then cherry-pick in the rest of the maybe-good commits excluding the known-bad commit.
Once you have this new branch, you can use git rebase -i
or git rebase --onto <target> <exclude>
to drop even more commits, if you like.