Revert specific git commits and all subsequent commits that depend on them

Viewed 48

I'd like to revert every commit K if and only if:

  • K is one of two specific commits I want to reverse
  • or, K depends on one or more of these commits I want to reverse

For background, I'd like to have a local copy of Flutter that reverses these changes.

1 Answers

You can tell if one commit (one of the two you want to revert) is an ancestor of another

git merge-base --is-ancestor <maybe-ancestor-commit> <descendant-commit>

So list every commits of every branch and:

  • if none of your 2 commits are ancestor of a branch HEAD, discard the branch
  • if they are, start enumerating commit from that branch

You might consider soft resetting that branch to before those commits: the index would be at the desired state: you can add and commit that index as one new commit which would reverse anything done since those commits (ancestors of a given branch)

Related