If you’re insane, use git-bisect
. Here's what to do:
git bisect start
git bisect bad
git bisect good <some commit where you know the file existed>
Now it's time to run the automated test. The shell command '[ -e foo.bar ]'
will return 0 if foo.bar
exists, and 1 otherwise. The "run" command of git-bisect
will use binary search to automatically find the first commit where the test fails. It starts halfway through the range given (from good to bad) and cuts it in half based on the result of the specified test.
git bisect run '[ -e foo.bar ]'
Now you're at the commit which deleted it. From here, you can jump back to the future and use git-revert
to undo the change,
git bisect reset
git revert <the offending commit>
or you could go back one commit and manually inspect the damage:
git checkout HEAD^
cp foo.bar /tmp
git bisect reset
cp /tmp/foo.bar .
git log --diff-filter=D -- path/to/file
– Maskanongegit checkout deletedFile
will undeletedeletedFile
if it's been deleted but that deletion has not yet been staged or committed. That's not what the question here is asking for; this question is about how to restore a file whose deletion was committed many commits ago. – Cesaria