Wednesday, 15 September 2021

Accidental stash delete?

If you've accidentally deleted a stash then worry not, you can recover it like this (thanks to my colleague Matt for this tip):

  • Run this in Git Bash terminal

    git fsck --unreachable | grep commit | cut -d ' ' -f3 | xargs git log --merges --no-walk


    It'll return a list of deleted stashes, ordered by date.

  • Find the commit hash in the response and then update the commit hash in the below cmd and run it

    git update-ref refs/stash 4b3fc45c94caadcc87d783064624585c194f4be8 -m "My recovered stash"


  • Refresh your git client (sourcetree/gitkraken) and it should now be listed again under 'Stashes'!

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!