Created
January 1, 2016 12:54
-
-
Save RonaldFindling/80055965f3c9c8d0f43c to your computer and use it in GitHub Desktop.
Recover staged and uncommited files after deletion by git reset --hard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#get hash-values for all unreachable files sorted by timestamps by Mark Longair http://stackoverflow.com/questions/7374069/undo-git-reset-hard-with-uncommitted-files-in-the-staging-area | |
find .git/objects/ -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort | cut -d " " -f 3 | sed "s/\.git\/objects\/\(.*\)\/\(.*\)/\\1\\2/" > file_hashes_to_recover.txt | |
#create git restore commands | |
# awk '{FS="\t"} {print "git show "$1" > recovered"FNR".pdf"}' file_hashes_to_recover.txt > file_recovery_commands.txt | |
awk '{FS="\t"} {print "git show "$1" > recovered"FNR}' file_hashes_to_recover.txt > file_recovery_commands.txt | |
#run the restoration commands | |
bash file_recovery_commands.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment