recovery - How to recover a dropped stash in Git? -
i use git stash
, git stash pop
save , restore changes in working tree. yesterday had changes in working tree had stashed , popped, , made more changes working tree. i'd go , review yesterday's stashed changes, git stash pop
appears remove references associated commit.
i know if use git stash
.git/refs/stash contains reference of commit used create stash. , .git/logs/refs/stash contains whole stash. references gone after git stash pop
. know commit still in repository somewhere, don't know was.
is there easy way recover yesterday's stash commit reference?
note isn't critical me today because have daily backups , can go yesterday's working tree changes. i'm asking because there must easier way!
if have popped , terminal still open, still have hash value printed git stash pop
on screen (thanks, dolda).
otherwise, can find using linux , unix:
git fsck --no-reflog | awk '/dangling commit/ {print $3}'
and windows:
git fsck --no-reflog | select-string 'dangling commit' | foreach { $bits = $_ -split ' '; echo $bits[2];}
this show commits @ tips of commit graph no longer referenced branch or tag – every lost commit, including every stash commit you’ve ever created, somewhere in graph.
the easiest way find stash commit want pass list gitk
:
gitk --all $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )
this launch repository browser showing every single commit in repository ever, regardless of whether reachable or not.
you can replace gitk
there git log --graph --oneline --decorate
if prefer nice graph on console on separate gui app.
to spot stash commits, commit messages of form:
wip on somebranch: commithash old commit message
note: commit message in form (starting "wip on") if did not supply message when did git stash
.
once know hash of commit want, can apply stash:
git stash apply $stash_hash
or can use context menu in gitk
create branches unreachable commits interested in. after that, can whatever want them normal tools. when you’re done, blow branches away again.
Comments
Post a Comment