1

I'm in process of merging two branches (using git mergetool), when I find a bug in one of the branches that warrants a fix in its own right. The fix is simple, but I'm one hour into merging the branches (and of course I don't want to lose my work), and it seems that it will take another hour to finish the merging (so I'll probably forget about it by then). What's the best way to deal with this situation?

Edit: the problem is that the bug will need to be fixed on the original branch too, which seems hard to do in the process of merging. Plus I don't know if it is good practice to fix the same bug in two different commits.

Imperishable Night
  • 1,503
  • 9
  • 19
  • Write it down? It's not like you can't change files while you're merging either. – Retired Ninja Nov 24 '17 at 03:08
  • Just finish the merge and then immediately make a commit to fix the bug. – Tim Biegeleisen Nov 24 '17 at 03:14
  • Ok, so write it down, finish the merge, fix it in the original branch, then merge again. Saying you're going to forget about it in an hour is just silly. But there's nothing stopping you from pulling the original branch into another directory and fixing the issue right then, then when you're done merging just merge again. – Retired Ninja Nov 24 '17 at 03:21
  • You won't be fixing the bug in two commits. Fix it in one branch, and merge again. (It doesn't really matter which branch the fix is committed to first.) – chepner Nov 24 '17 at 03:24
  • @chepner I will still need to wait until the merge finishes, which is a pain. If this (finding an unrelated bug) happened during my normal work, I can always stash my work away, fix the bug, then pop my stash. – Imperishable Night Nov 24 '17 at 03:29

1 Answers1

1

I prefer not mixing two tasks, especially if one of them (merge) is long and complex.

With git worktree, you can make a second working tree out of the same cloned repo: see "Multiple working directories with Git?".

In that second working directory set on the right branch, fix your bug.

Once your merge completed, merge again, this time including the new commit fixing your bug.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250