microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.07k stars 29.21k forks source link

Git conflict resolution Accept Current Change "ignores" addition of a single empty line #123721

Open erhhung opened 3 years ago

erhhung commented 3 years ago

I'm resolving a merge conflict where the last diff is the following (I had already resolved a couple successfully earlier in the file):

Current ChangeIncoming Changes

154:  same line in file  |  154:  same line in file
155:                     |
156:  another same line  |  155:  another same line

Basically, just an empty line inserted by the current change.

Add I see this in the merge interface:

154:  same line in file
     Accept Current Change | Accept Incoming Change | Accept Both Changes | Compare Changes
155: <<<<<<< HEAD (Current Change)
156:
157: =======
158: >>>>>>> master (Incoming Change)
159:  another same line

If I click on Accept Current Change, the empty line was not preserved—in fact, if I undo and click Accept Incoming Change instead, the result is the same!

Does this issue occur when all extensions are disabled?: not tested

Originally reported under and possibly related to: https://github.com/microsoft/vscode/issues/107821#issuecomment-831657432

vscodebot[bot] commented 3 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

ReveStobinson commented 3 years ago

I experienced this error as well today. Steps to reproduce: create git repository with any text file in it. I used this python file, which I named test.py:

import sys

print("Hello world, this is python version " + sys.version)

for x in range(1, 6):
    print(x)

print('Goodbye!')

Create a new branch based on HEAD, I named mine new_for_merge. In test.py on the new branch, I added a line between lines 4 and 5. So the file looked like this:

import sys

print("Hello world, this is python version " + sys.version)

for x in range(1, 6):
    print(x)

print('Goodbye!')

Then I made a similar change in the master branch, but added some text on that line:

import sys

print("Hello world, this is python version " + sys.version)

sys
for x in range(1, 6):
    print(x)

print('Goodbye!')

Then from new_for_merge, I attempted to merge master into the current branch. This results in a merge conflict:

import sys

print("Hello world, this is python version " + sys.version)

<<<<<<< HEAD

=======
sys
>>>>>>> master
for x in range(1, 6):
    print(x)

print('Goodbye!')

And within VSCode, it presents me with the options "Accept Current Change", "Accept Incoming Change", "Accept Both Changes", "Compare Changes". Hitting "Accept Current Changes" should keep the file the way it currently is, which in this case would mean adding a blank line after line 4. But when I hit "Accept Current Changes" in VSCode currently, the line gets removed entirely, keeping neither the current nor incoming changes! (So my file now looks like the first code block, when the expected behavior would be looking like the second)

VSCode version info: image

This issue does still occur even when all extensions are disabled, and other git GUI programs do not have this problem, and can properly handle accepting the changes.

dkl commented 1 year ago

It seems to happen with both Accept Current Change or Accept Incoming Change, but not Accept Both Changes. Example file with git merge conflict markers:

Example 1: Clicking on "Accept Current Change" should preserve the current empty line, but does not.
(but it works when clicking "Accept Both Changes" or if there are multiple empty lines)
<<<<<<< HEAD

=======
>>>>>>> other_branch
trailing line

Example 2: Clicking on "Accept Incoming Change" should preserve the incoming empty line, but does not.
(but it works when clicking "Accept Both Changes" or if there are multiple empty lines)
<<<<<<< HEAD
=======

>>>>>>> other_branch
trailing line

(VSCode 1.79.2, no extensions loaded)