Can I synthesize a branch in git that skips a single change set
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.
- How to debug Cannot run program “C:\Program Files\Git” in a Jenkins job?
- Are Git submodules a good idea to NOT force library users to download its tests?
- How to test code from a Git branch without merging it with master branch?
- Git: forcing tests before pushing to local or remote master
- Play framework 2.0 continuous integration setup
- How to optimize testng and seleniums tests
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 ]
2 Solutions collect form web for “Can I synthesize a branch in git that skips a single change set”
git checkout -b newbranch <specifier-for-B> git cherry-pick <specifier-for-C>..<specifier-for-G>
<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.
You could interactively rebase and remove that commit.
First create the test branch:
git checkout -b test
Next, start the rebase:
git rebase -i C^ # the parent of C
When you are in the interactive rebase screen, delete the line that contains commit
This will make the
save branch effectively match
A -> B -> D1 -> E1 -> F1 -> G1 and you can continue your testing.
If you find that
C was the only commit you need to remove, another option would be to revert it so you don’t need to push any history that modifies already-pushed commits:
git checkout master # get back to where you started git revert C # will create a revertion commit git push # will only push 1 new commit, the inverse of C