Undo 'Discard chunk'



Is there a way to undo the effects of the "Discard chunk" button in a git diff window?

I found it is too easy to click one these buttons by mistake while reviewing changes. Without warning, several lines of your carefully crafted code seems to be gone from editor, no longer present in your saved file, and were never in your repo in the first place (as you were just about to commit). Surely there should be a way to undo this?!

Thank you!


Looking around for solutions, it seems like the solution (at least for GitHub desktop) was to add a confirmation step (the thread also links out to some possibilities for trying to get the changes back, but they're a bit beyond my personal level of Git-fu):


Thanks Mara for looking into this.

IMHO, for 'discard chunk' would also make sense to add a confirmation step, and/or saving a backup version somewhere. While less code is lost irretrievably here (compared to a full revert), pressing the button is way too easy; it is right next to 'stage chunk', and it also can 'jump under the mouse' due to a delayed reaction to some previous action. (This latter happened to me, good thing I still remembered and could redo the needed changes.)

Also, here as well, git will not help much as discard chunk would discard changes done on top of the latest HEAD, which changes would normally not be available in the repository.


Makes sense. You can feel free to submit a feature request for the IDE:

This guide will help you along:
RStudio IDE Guide: Writing Good Feature Requests