Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stage single deleted lines in Visual Studio Code

I'm using Visual Studio Code and its integrated version control. I would like to split a group of deleted lines in two different commits.

I know about the "Stage Selected Ranges" option but, from what I see, I can't select deleted lines.

Is there a way to achieve it?

Thanks

enter image description here

like image 221
Fab Avatar asked Jul 26 '19 08:07

Fab


1 Answers

I'm afraid there is no way to do what you want with VS Code.

It's not a VS Code problem, it's a git problem. git is telling VS Code to treat those consecutive changes as one hunk, and so if git can't split it, then VS Code can't either.

Try running git add -p on the command line, and you'll probably see that git treats those changes as one hunk since they are pretty close to each other. Try passing s on the git add -p prompt, and if it says "Sorry, cannot split this hunk", then VS Code can't either.

I think the only way is by manually editing the patch file with git.
See: Can I split an already split hunk with git?

There were requests for VS Code to support patch file editing like this: https://github.com/Microsoft/vscode/issues/69891, to which the response was:

We try to keep VS Code lean and we think the functionality you're asking for is great for a VS Code extension. Maybe you can already find one that suits you in the VS Code Marketplace.

AFAIK, the only patch-related extension is Git Patch. It allows you to create patches from staged/unstaged changes, but it does not let you select which changes to add to the patch. You'll have to edit the patch manually, discard your changes, then apply the patch one by one. It's pretty much the same as doing git add -p and then passing e.

like image 115
Gino Mempin Avatar answered Sep 28 '22 04:09

Gino Mempin