1

Here's a diagram of my situation, the dots representing commits (this is actually from SourceTree; I've turned it on its side to make it easier to see, with time flowing left to right):

enter image description here

This is due to a mistake (caused by an interactive rebase that created an extra branch — I don't know why). I would like to remove all the blue dots (commits) in the upper row between the endpoints, leaving only the left endpoint, the lower row (red dots), and the right endpoint. Can I? Nothing has been pushed (there is no remote); I'm just trying to clean up my history.

matt
  • 515,959
  • 87
  • 875
  • 1,141

1 Answers1

1

All you have to do is fix the final blue commit on the right. It has two parents, a blue and a red commit, and you want it to have just the red parent. If you edit the commit and remove the blue parent, the entire blue line of commits will effectively disappear from your commit history since there will be no commits listing them as ancestors.

See: Remove spurious commit parent pointer

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • Save the SHA hash of your current commit (or check the `reflog` after the fact). You can always undo any damage you've done by resetting your HEAD/branch to that commit hash. Worst case, if you destroy everything doing some complicated edit/rebase/filter you just go back to the hash and it's all undone. – John Kugelman May 06 '19 at 00:36
  • Well, it worked great, I'm compelled to admit. :) – matt May 06 '19 at 02:05