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.

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 ]

  • How to handle a Git repository with >100k test files?
  • How to simulantenously work on multiple branches while waiting for tests to to run?
  • Do you have to run test locally when you have a CI server?
  • What is a right way to deal with tests, temporary files and version control
  • Git: Run through a filter before commiting/pushing?
  • Emulate Git repo in JUnit
  • Beta testing new website features with live data and real customers
  • How to list the slowest JUnit tests in a multi-module Maven build
  • 2 Solutions collect form web for “Can I synthesize a branch in git that skips a single change set”

    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.

    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 C.

    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
    
    Git Baby is a git and github fan, let's start git clone.