How to undo "Discard" if not committed

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


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

For me I'm using mac when I discard file and I want to get back

I open that file and open with

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.

Thanks and regard; sambath chea

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.

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:

(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.

Need Your Help

Implicit conversion from int to varchar

sql sybase

SET @waveperiod = convert ( varchar,@value ) + convert (varchar,@value2)

using mysql_real_escape_string in blind code

php mysql security sql-injection mysql-real-escape-string

I have a client which has very large amount of code on its production server, now we are securing this server.