How can I undo discard changes in GitHub Desktop?
Asked Answered
A

14

42

Is there any way to undo discard changes in GitHub Desktop, after the Undo button has disappeared?

enter image description here

I am talking about GitHub Desktop's undo feature, not git in general.

Astonishing answered 22/2, 2016 at 5:4 Comment(2)
@TheGeorgeous Thanks, if I use Git Shell, which command should I run?Astonishing
You can check recycle-bin once.Sometimes discard file are there in recycle bin and you can restore the same but remember the version you have discarded will only appear. If you have done changes after discarding that will not merge into it.Almira
F
2

Emailed the Github support team and was told that after this option disappears, there is no other way to Undo the change. They may implement this feature at a future time.

Formulism answered 9/3, 2017 at 21:32 Comment(1)
This answer is for an outdated versionMainly
M
67

As of 5/8/18, and if you're using the latest version of github desktop or github desktop beta, uncommitted discarded changes are now copied over as new files and put into your trash/recycling bin.

This is what the current prompt looks like:

enter image description here

Mainly answered 8/5, 2018 at 18:36 Comment(0)
M
49

First of all, Don't Close the VS Code.

Then open all the Files Where you have done Discard Changes.

Press Ctrl+z for Undo & CTRL+S for saving the changes.

It's worked for me.

Mumble answered 9/5, 2020 at 16:34 Comment(2)
life saver! thanks a ton! <3Wantage
I should not upvote this answer technically (OP asked for a Github Desktop solution, no matter the IDE), but this helped me a lot, thanks! You should make a self-answered question for VS Code + Git.Latona
S
32

when you're using VS Code, don't close it, go to the file you discared the changes, right click on it, and go to "Open Timeline" and there you'll find all the changes you made on that file, then you can easily get back your last changes :)

Superstitious answered 23/9, 2022 at 11:17 Comment(8)
This is some good stuff man! THANK YOU!Thessa
I logged in from work laptop to thank you. I lost changes I had been working on for a week (new to git) and this reply helped me get them back.Malissamalissia
This answer save my life, Thank you soo muchGuanine
Thank you so much! I probably mistakenly discarded the changes 2 weeks ago and just noticed it today.Diphenylamine
This allowed me to get deleted file also back just recreated the file with same name and through Timeline I got my code back. Saved my weeks work.Parra
Accidentally discarded some file changes, Glad I found this answer.Joyejoyful
Is there a way I can buy you a coffee please? I was working for two days on a script and I accidentally deleted it, went to VsCode Source control and discarded the deleted file, it also took my changes. Thank you so much @SuperstitiousBirchfield
@AdnanSheikh it's like you bought me the coffee :) thanks and happy that i helped youSuperstitious
P
16

You can find those discarded files in the recycle-bin.

Pyrrolidine answered 17/9, 2018 at 7:52 Comment(0)
R
9

GitHub Desktop Menus -> Repository / Restore Discarded changes

Ravishment answered 26/3, 2016 at 3:6 Comment(2)
Where is the GitHub desktop Menus?Meshuga
This menu item has been removed, see this answer: https://mcmap.net/q/381619/-how-can-i-undo-discard-changes-in-github-desktopMainly
F
2

Emailed the Github support team and was told that after this option disappears, there is no other way to Undo the change. They may implement this feature at a future time.

Formulism answered 9/3, 2017 at 21:32 Comment(1)
This answer is for an outdated versionMainly
C
2

I'm using Github Desktop for Windows v2.1.0 and I can confirm the trash/recycling bin doesn't exist any more. I'm using Windows 10.

In my case, the discarded change I wanted to undo was a deleted folder.

What solved it for me was to open the parent folder in Windows Explorer and do ctrl+z. This restored my deleted folder.

Coltson answered 5/8, 2019 at 7:12 Comment(0)
V
2

I got he same situation, just went to the Bin and the files were there. Just needed to replace the code manually again. My machine: Mac.

Vonnie answered 7/2, 2022 at 9:28 Comment(1)
[windows OS] you can simply restore from the recycle bin. and replace the existing old versionStylobate
U
1

I went to Windows 'Recycle Bin' and found all my files.

Choose 'Restore' the files option of ‘Recycle Bin’ and then select 'Replace the file in the destination' option, all the changes should be back.

I had discarded the changes in the 'GitHub Desktop' still manage to restore it.

Unreconstructed answered 8/3 at 2:59 Comment(0)
S
0

The discarded change is sent to the trash as a new file, with some variation of the original file's name. You can copy and paste the file in the trash to the original file.

For example: I discarded a change to package.json, and the resulting file in the trash was named package 16-36-10-974.json. This file contained the original contents of the file before I discarded it. I copied the contents from package 16-36-10-974.json to package.json, and that's how I got the discarded changes back.

(not sure where the numbers in the file name come from)

Sliwa answered 15/5, 2019 at 23:56 Comment(0)
A
0

I had this issue and it appeared that there was no way to restore these files using GitHub Desktop, my files were hosted on one of our servers but for some reason GitHub Desktop didn't move the files to the recycle bin as stated. Thankfully the server was backed up and I was able to restore the files that way.

Aggappera answered 16/5, 2019 at 11:16 Comment(0)
M
0

I used Recuva and it worked.

Just install the app and select the folder that you need to recover, wait 2 mins

Mitchelmitchell answered 21/7, 2020 at 20:1 Comment(0)
I
0

If you have ide open in which you coded, just undo changes by ctrl + z. All your discarded changes will be back.

Isologous answered 4/4 at 3:46 Comment(0)
I
-1

You need to recover those files from the git repo

git fsck --unreachable --no-reflogs --no-cache HEAD

Or check it out this one:- restoring lost commits

Interlanguage answered 18/3, 2016 at 6:48 Comment(1)
This only applies to files that actually were committed, in this case, we're looking for files that were never staged or commitedMainly

© 2022 - 2024 — McMap. All rights reserved.