I am using VS Code, and I am constantly annoyed when I find a typo in a staged change just before a commit (usually in the read-only "(Index)" editor). Because resolving it involves opening the original file, finding the same location, making the change, saving the file, now opening the diff of the file, staging this change (and none of the others), then finalizing the commit. This seems unnecessary complicated to me.
I would just like to make edits to the index - a smart editor such as VS Code should be able to do what's necessary in the background. But it won't let me since the editor is read-only, and I "Cannot edit in read-only editor"
There is a GitHub issue#91065 (and #91274, #74149, #15785, #33681) on this, saying this works "as designed". But the explanation does not really explain it to me:
The title of the diff says
(Index)
- this means you have staged the changes, and you are diffing the staged changes against the head revision.
Correct, but that does not explain why VS Code should not be able to stage further changes.
This is not the same as the working file, because you can selectively stage some parts of the file, so the stage version may look different to the working file
Again: correct, but that does not explain why VS Code should not be able to stage further changes without going through the hassle of editing the "working file" first.
You cannot edit the right side because the changes are staged
That's not an explanation to me.
you need to edit the working file and stage those changes as well, or unstage and edit the file
And finally, again, I don't see why VS Code could not do that for me.
But maybe I am overlooking something. So my question is,
The only answer here is, find a VS Code plugin as good as the ones written for vim (fugitive) or emacs (magit). Both of those treat the index as just another directory on a different filesystem, I don't know magit but fugitive lets you edit :path/to/file
directly, and with :Gdiff
you can nab diff hunks from that or from arbitrary revs, basically that's the power-tools version of add --patch and reset --patch and checkout --patch. I'd be shocked if it turns out magit can't do that.
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