Recover dropped Stashed Changes in Github Desktop (Windows 10)
Asked Answered
U

1

6

Using Github Desktop (v. 2.9.6 on Windows 10) as beginner, when moving back and forth from branch to branch, I stash my changes to keep them on a branch for later. But doing this twice in a row, instead of stacking the changes in the stash, it actually overwrites and drops the previous stash.

I have therefore lost multiple changes. Github desktop does not offer an option to recover these, although they should be recoverable using command lines (see here: How to recover a dropped stash in Git?). But a Shell command line is no longer readily available in Github desktop. Also the discarded files were not available in the windows Recycle Bin, and trying to cancel using ctrl+Z didn't help.

This question is also similar to thread How can I undo discard changes in GitHub Desktop?, but the thread is closed without satisfactory answer. Accepted solution simply says that Github desktop staff confirmed there is no way to recover such discarded changes.

Untouched answered 21/12, 2021 at 22:3 Comment(1)
If you're on macOS, use terminal as your command line. If you're on Windows, use Powershell. Then try the stuff in the question you linkedArmbrecht
U
19

A Stash dropped in Github Desktop on Windows 10 can be recovered in the following way:

  1. Find the $stash_hash address of the dropped stash in the Logs of Github Desktop:
  • Visit this folder: C:\Users\USERNAME\AppData\Roaming\GitHub Desktop\logs

  • Open the log file of the day stash drop happened.

  • Locate the line that says "Dropped stash", it contains the hash address (in my case 92de3e8c594356cf04169d68e9cdf634806ab315). See Screenshot from Github Desktop Log File

  1. Enable Windows Command Prompt to seamlessly write Git command using the same git.exe as Github Desktop. The following thread explains it all: https://mcmap.net/q/336003/-where-does-github-desktop-install-command-line-version-of-git
  2. In Windows Command Prompt, navigate to the folder containing your repository and enter the following command: "git checkout -b recovery $stash_hash" where $stash_hash is the hash address of the dropped stash. This will create a new branch called "recovery" in the repository where all previously dropped stashed changes are committed. This is taken from: https://mcmap.net/q/11480/-how-do-i-recover-a-dropped-stash-in-git
Untouched answered 21/12, 2021 at 22:24 Comment(3)
The folder on macOS is /Users/USERNAME/Library/Application Support/GitHub Desktop/logs. You can also use the Help tab in the menu bar and click on the Show logs in Finder option.Pronoun
You are a life saver. I didn't realize that stashes aren't all saved separately, and will get lost once used.Kremer
This only works if you manually discard a stash from within GitHub Desktop. If you accidentally overwrite it with a new one when switching branches, it does not log the replacement of the stash entryEmbalm

© 2022 - 2024 — McMap. All rights reserved.