1

I have two git branches I'm working on, let's call one problem-fix and the other problem-fix-dev. The dev branch is connected to a personal remote pipeline I'm working on, so I've been including all sorts of debugging and logging statements for testing purposes. Now that I've finished my fix, I want to merge it into problem-fix, but obviously don't want to include the various printing and logging code.

I could go through the code and just delete all the undesirable lines, but that would be very tedious. And it won't be as simple as deleting all lines that begin with print for various reasons. Additionally, I can't just git rebase and selectively drop commits, since many of the commits I've made have both undesirable printing lines as well as important fix code.

So my question is: is there a way to force git to show differences between branches in editor, ideally with the merge conflict syntax? While I'm sure there are no actual existing conflicts, my life would be made a lot easier if each change was highlighted in the editor line by line.

Alternatively, I'm using VSCode. So if there is a nifty extension or plugin that can accomplish the same thing, that would be fine.

Thanks

  • 1
    Are the two branches fixing the same thing, but one has extra logging you don't need? – TTT Jun 23 '21 at 18:10
  • Pretty much. `problem-fix` is a shared branch that is attached to a Pull Request. Since I need to push changes to test them (they get pulled in by the remote pipeline). I don't want to muddy the PR with my messy logging. `problem-fix-dev` is my personal branch just for testing, but is fixing the same problem. Probably messy but seems to work so far, other than this issue. – user10925336 Jun 23 '21 at 18:57
  • BTW, I find myself in a similar situation occasionally, and one thing that sort of works is to keep debug code that you know you will eventually strip out, in separate commits. This is much easier to do if you have an editor that can stage "hunks" (VSCode is one). Then you don't have to do it all at once at the end when you're done. – TTT Jun 24 '21 at 13:54
  • 1
    Yeah this is definitely the way to go, I just wasn't maintaining a good workflow. The solution below fixed my issue but I should probably be better about separating commits in the future. – user10925336 Jun 24 '21 at 15:23

1 Answers1

1

This is what you could do:

  1. Undo all the commits but keep the changes in the working branch (e.g. git reset head~4)
  2. Review your changes and undo all unneeded changes (I personally use TortoiseGit for this, there I could undo files or lines in files - it visible with a two panel merge view)
  3. Create a new commit
Julian
  • 33,915
  • 22
  • 119
  • 174
  • While not exactly what I was looking for, this was the easiest for me to use. Coupled with VSCode's git plugin, it was easy to see the changes I had made and select the right ones. Thanks! – user10925336 Jun 23 '21 at 18:34