I have a local branch in which I did some development, the commit history is pretty bad so I am going back and rebasing to tidy up and leave it in a sensible state before pushing.
Say I have commits A, B, C, D, E. In commit B I have added some useful code that I want to keep but I also added some debug code. I then later removed the debug code in D. What is the best approach to use to remove this entirely from the history (the code isn't of any use so I don't want it in the history if possible)?
I have tried rebasing at A, rewriting the commit at B without the code but then C and D need manual intervention at each rebase step. Is it best to split B,D into B-keep and B-remove and D-keep and D-remove then remove the two commits? Is there other ways to clean up when code has been added then removed?
I want to end up with history that looks like A, B(useful), C, D(useful), E which I then may squash to A, B, E for example, at this stage I just want to remove the debug code from the history.