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
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With