0

Is there a way to prevent the lines to be removed during the merging and make them available in the produced output (in a distinguishable form)?

Ideally, I want to keep lines "to be removed" as commented.

But it would be totally ok if there is a way to force merge to behave as it is a conflict situation (even if there are no conflicts at all), in order to produce the source with <<<<<<< ======= >>>>>>> markers in it.

I've tried to use hunk by hunk patching, using git add -p and then choosing "e" option for editing. But seems that it doesn't allow line's content to be edited.

Martin Babacaev
  • 6,240
  • 2
  • 19
  • 34
  • Playing the devil's advocate, do you _really_ want all that stuff in there as comments? Most IDEs (e.g. IntelliJ) with Git integration make it very easy to visually trace back the history of a file, find removed content, etc. I'd rather rely on that then maintaining void information in my source files. – Tim Biegeleisen Dec 19 '17 at 11:33
  • I agree, it's not something I want to do all the time. It's just an exceptional case. – Martin Babacaev Dec 19 '17 at 11:38
  • There is a way to force Git to never do an auto complete of a merge on a file. If you poke around SO, you will find it. If I recall correctly, it is fairly draconian. – Tim Biegeleisen Dec 19 '17 at 11:44
  • You need to provide some actual examples, because I do not understand exactly what you want here. – hlovdal Dec 21 '17 at 09:08
  • From my guessing, it sounds like you want to keep (parts of) undo of a merge for some time. Maybe you can make this by merging normally, running `git diff $AFTER_MERGE $BEFORE_MERGE | git apply -; git add -p; git commit -m "=== merge undo ==="`. Keeping the undo information in a `distinguishable form` is easy when you [mark the commits specially](https://stackoverflow.com/a/26700877/23118) instead of trying to do something with the code (although you might want to comment it). – hlovdal Dec 21 '17 at 09:16
  • Although I have to say keeping commented code around in the source is a horrible anti-pattern that you should refrain from performing. – hlovdal Dec 21 '17 at 09:17

0 Answers0