26

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

nwellnhof
  • 32,319
  • 7
  • 89
  • 113
BPL
  • 277
  • 1
  • 3
  • 4

8 Answers8

38

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

Ghazanfar Mir
  • 3,493
  • 2
  • 26
  • 42
32

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.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Chea Sambath
  • 1,305
  • 2
  • 13
  • 16
4

Open this file in IDE and Press Command + Z

Vu Thanh
  • 319
  • 1
  • 14
3

In Intellij,

You can check the local history and revert back.

Jacob Joy
  • 489
  • 6
  • 7
1

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.

Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80
  • Note there's a small exception here: if the changes got added to the index, but not committed, they are still recoverable. (See [answers](http://stackoverflow.com/questions/10782978/recover-files-that-were-added-to-the-index-but-then-removed-by-a-git-reset).) – Asherah Oct 14 '16 at 04:54
1

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'.
mathi
  • 17
  • 1
  • 5
0

There isn't any way to get your changes back via git or sourcetree as of sourcetree 1.8.1 for Mac; see the discussion here:

https://jira.atlassian.com/browse/SRCTREE-2090

(If you login to jira, you can also vote for this to be implemented!)

When I did this, I was able to get the changes back as the file was in my time machine backup.

JosephH
  • 37,173
  • 19
  • 130
  • 154
0

If you have lost a javascript or template file, there's a chance you will find it in the browser if you were debugging it and haven't reloaded.

intotecho
  • 4,925
  • 3
  • 39
  • 54