How can I quit an in-progress git merge operation in VS Code?
Asked Answered
L

2

7

I'm working on a project in VS code. I made changes, pulled from GitHub and got merge conflicts. I don't know what i did but my merge conflict screen now looks like this (it's highlighting the file as one big merge conflict?). I don't want to delete any of my progress in this file. Is there a way to "reset" (quit) the merge so I can try merging again?

enter image description here

Levi answered 14/4, 2023 at 20:25 Comment(2)
you have a merge conflict, any way you want to incorporate the new stuff you have to resolve the conflict, best to do it now, use VSC ar merge conflict tool or any other 3 way merge tool, or do it by editing the file with a conflict unaware editor, search for the conflict markers, use git status to see what git expects you to doOof
And to emphasize: you really want to use a proper 3-way merge tool (which sort of despite its name has four windows/panes). KDiff3 is such tool and you can use my script to launch it with the correct arguments. (Despite Microsoft's claims, what they have is not a proper 3-way merge tool)Hazelhazelnut
S
12

You can use the Git: Merge Abort command in the command palette. Its command ID is git.mergeAbort (you can use this to bind it to a keyboard shortcut). The command pretty much just does git merge --abort. Courtesy of feature-request #152525.

Just running git merge --abort in any terminal in that git repository should work too because it's the underlying operation of the command palette command. It doesn't even have to be in VS Code's integrated terminal. VS Code's builtin Git extension watches for externally driven changes.

Superstratum answered 14/4, 2023 at 20:29 Comment(0)
M
0

None of these suggestions worked for me. I did run git merge --abort from the command line, but there was no evidence of whether it worked or not.

I couldn't get anything useful to show up in the command palette.

I tried quitting VSCode, but it just dumped me back into the same horrible Merge Compare view.

Finally, I realized I could just close the file, close the merge view, and start over.

This is a terrible UX if you're trying to do refactoring across multiple branches - it only seemed to give me the option to accept all incoming changes, not pick and choose.

Anyway hopefully this helps someone else - you'd think there would be an easy way to get in and out of any kind of view, i.e. hit escape, or command-z to undo, but I couldn't figure out how to cancel out of this view without being stuck with changes I didn't want to save.

Mcinerney answered 18/9 at 16:25 Comment(2)
"but there was no evidence of whether it worked or not." run git status. or see the answers in https://mcmap.net/q/545305/-git-determine-if-branch-is-in-a-merge-conflict-state/11107541Superstratum
if the merge editor doesn't auto-close when aborting the merge, I'd suggest raising a feature-request issue ticket asking for that to happen. if you raise a ticket, please add a link here to the ticketSuperstratum

© 2022 - 2024 — McMap. All rights reserved.