0

I accidentally deleted a large number of LaTeX files by using git stash instead of git stash -u. I have recovered a bunch of them following the instructions here using the command:

git fsck --full --no-reflogs --unreachable --lost-found | grep blob | cut -d\  -f3 | while read in; do printf "blob: $in\n"; git cat-file -p $in; printf "\n--------------------------------\n"; done > recover.txt

The problem is this includes a bunch of junk like log files, I would like to modify this command so that I only recover files that include the words "\begin{document}" inside them. It seems like this should be easily doable by modifying the grep step in the code above, but I do not understand the copied code well enough to do this myself.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Noah Snyder
  • 101
  • 1
  • 3
  • 3
    `git stash` doesn't exactly delete files: it makes a *commit* out of files. In fact, it makes at least two commits, and with `-u`, makes three commits. Without `-u` it commits only the staging area and the working tree files that are listed *in* the staging area, and you can easily restore everything exactly as it was before with `git stash apply --index`. There should be no need to find anything. – torek Dec 07 '21 at 04:17
  • 3
    If the `git stash apply --index` works, be sure to eventually use `git stash drop` to delete the stash. If it doesn't work, you still have the stash. In either case, I recommend avoiding `git stash`: it's too complicated and doesn't do anything you can't do with simpler commands (although they will require a bit more manual work). – torek Dec 07 '21 at 04:18
  • Ah, nevermind, I figured out what you were saying and you were right. – Noah Snyder Dec 07 '21 at 05:25
  • 3
    What is this blog post with content scraped from this [Stackoverflow answer](https://stackoverflow.com/questions/11094968/in-git-how-can-i-recover-a-staged-file-that-was-reverted-prior-to-committing)? But happy that my command helped a little... – Philippe Dec 07 '21 at 06:56
  • 2
    Please note that newbedev is a Stack Exchange scraper; don't link to it. Instead, google the text or title, and find the correct link to the network, instead of giving scrapers more traffic that they don't deserve. – Zoe Dec 26 '21 at 16:54
  • 1
    @Philippe see that ^ -- it's one of many SE scrapers, with the minor difference that they some times obfuscate and reduce content. Not sure how, but several scrapers heavily outranks SO. If you see any in the future, feel free to edit in the correct URL and notify OP that it's a scraper. Sadly not much else to do about it: SO doesn't care anymore, and doesn't do takedowns like they used to, in spite of a few of these garbage sites outranking SO – Zoe Dec 26 '21 at 16:56
  • 1
    @Zoe: Thanks for the edit. Most of the scraper sites are obvious, but that one fooled me with the reformatting that didn't look like a Q&A. – Noah Snyder Dec 26 '21 at 19:39

0 Answers0