BPL
BPL

Reputation: 287

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

Upvotes: 27

Views: 30034

Answers (9)

rammstein
rammstein

Reputation: 57

If you use Visual Code check local history.

Bottom left -> Explorer -> Timeline -> you can see the changes made.

Upvotes: 0

Chea Sambath
Chea Sambath

Reputation: 1335

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.

Upvotes: 34

intotecho
intotecho

Reputation: 5684

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.

Upvotes: 0

mathi
mathi

Reputation: 17

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

Upvotes: 1

Vu Thanh
Vu Thanh

Reputation: 398

Open this file in IDE and Press Command + Z

Upvotes: 4

Jacob Joy
Jacob Joy

Reputation: 556

In Intellij,

You can check the local history and revert back.

Upvotes: 4

Ghazanfar Mir
Ghazanfar Mir

Reputation: 3541

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

Upvotes: 39

JosephH
JosephH

Reputation: 37505

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.

Upvotes: 1

Scott Berrevoets
Scott Berrevoets

Reputation: 16946

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.

Upvotes: 1

Related Questions