43

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.

2
  • 2
    @TheGeorgeous Thanks, if I use Git Shell, which command should I run? Commented Feb 22, 2016 at 23:20
  • 7
    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. Commented Apr 26, 2018 at 6:33

14 Answers 14

68

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

0
50

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.

2
  • 2
    life saver! thanks a ton! <3 Commented Oct 11, 2023 at 11:56
  • 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.
    – Rafael
    Commented Jan 28 at 3:08
33

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 :)

9
  • 2
    This is some good stuff man! THANK YOU!
    – Symlis
    Commented Jan 27, 2023 at 14:46
  • 1
    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. Commented May 3, 2023 at 13:33
  • 2
    This answer save my life, Thank you soo much
    – Husmukh
    Commented Jun 5, 2023 at 19:16
  • 1
    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 @Sofiane Commented Apr 6 at 11:22
  • 1
    @AdnanSheikh it's like you bought me the coffee :) thanks and happy that i helped you
    – Sofiane
    Commented May 10 at 13:59
16

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

9

GitHub Desktop Menus -> Repository / Restore Discarded changes

2
3

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.

2
  • [windows OS] you can simply restore from the recycle bin. and replace the existing old version
    – Irshad
    Commented Dec 21, 2022 at 8:08
  • Same here (also on a Mac.) I just copied the files out of the trashcan and overwrote the files in my project directory and was able to recover my work.
    – Duncan C
    Commented Aug 5 at 19:52
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.

1
  • 12
    This answer is for an outdated version
    – chrismarx
    Commented Jun 6, 2018 at 16:34
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.

0
2

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.

1
  • This answer just saved my butt. Thank you! I meant to discard spurious changes to a single file that my IDE keeps inserting into my project, and discarded an entire day's work instead. Thankfully the files were in the recycle bin/trashcan as you say.
    – Duncan C
    Commented Aug 5 at 19:51
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)

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.

0

I used Recuva and it worked.

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

0

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

-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

1
  • This only applies to files that actually were committed, in this case, we're looking for files that were never staged or commited
    – chrismarx
    Commented Jun 6, 2018 at 16:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.