Situation: I have a single git commit (at HEAD), which has mixed extra logging code, and then some "real code".
Now I would like to do the following:
- Edit out all the logging code, basically clean up the codebase
- Commit this
- I now have the desired states in the last two commits, but they are in the wrong order, first everything is added and then logging is removed, when I want other code added and then logging added
- Swap these two commits so, that
- first the actual feature gets added without the logging
- then the logging code gets added in its own commit
Now I could do this "by hand", by taking a plain copy of the code with logging included, then remove logging as desribed above and squash these commits into one (so there is no logging code in the commit history at all), then restore the copy of the code with logging included, and add that as a new commit.
But is there a way to do this elegantly and with less chance of human error using git features?
To clarify, I do not want to pick which parts to include in the first commit I desire (because there's a lot of small changes there and I don't want to review them again). I want to pick which parts to remove from the first commit, and add as a new 2nd commit.