How to undo "Discard" if not committed
Solution 1
I know the post is too old but I faced the similar situation and accidentally clicked "Discard" in SourceTree and lost my changes.
Luckily I had the IDE opened, i.e. PHPStorm, at the time. Though it had already refreshed the file I was working on and loaded the old copy after Discard, however, I did "undo" on the working file in editor and it loaded back my changes.
I saved the file and got my lost changes back.
Just wanted to share in case others face the similar situation as mine and want to recover their changes with little presence of mind :D
Solution 2
For me I'm using mac when I discard file and I want to get back
I open that file and open with TextEditor.app
on the top bar click File -> Revert To -> Browse All Version...
Select on last save version that you want hope it can save your time.
Solution 3
Open this file in IDE and Press Command + Z
Solution 4
In Eclipse,
- Right-click the discarded file from Package explorer
- Click 'Replace with'
- Click 'Local History'
- Compare dialog open with list of revisions
- Select your revision and click 'Replace'.
Solution 5
I don't believe you can do anything. If you didn't commit the changes at any points, there is no way to get them back after you discard them.
Related videos on Youtube
BPL
Updated on January 07, 2022Comments
-
BPL over 2 years
I accidentally clicked Discard while committing my changes. So I discarded the whole file but I wanted to discard only some hunk. But I haven't clicked on Commit, I did Cancel.
But now I cannot see my code in my file.
What can I do to undo the damn discard ?
Thanks in advance
-
Asherah over 7 yearsNote there's a small exception here: if the changes got added to the index, but not committed, they are still recoverable. (See answers.)
-
Deirdra Strangio about 5 yearsI tried this but TextEditor said I had no previous versions O_O
-
Chea Sambath almost 5 yearsBecause you did not save it before
-
Renatas M. almost 5 yearsThanks! Same thing applies to IntelliJ. Accept when you get "undo reset from file?" question when you hit Ctrl+z.
-
Chammi Weerasekera over 4 yearsThanks for saving my day! Works for
eclipse
as well. -
Tiago Mendes over 2 yearsDid work great for Swift file and Xcode...thank you :D