Skip to content

Instantly share code, notes, and snippets.

@infusion
Created May 22, 2016 22:23
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save infusion/b2cfefbea3fd0f601eec9755c69a7b66 to your computer and use it in GitHub Desktop.
Save infusion/b2cfefbea3fd0f601eec9755c69a7b66 to your computer and use it in GitHub Desktop.
Find and restore a deleted file in a Git
# Find last commit for the deleted file
git rev-list -n 1 HEAD -- $path
# Checkout the commit before the the delete happened
git checkout $commit^ -- $path
@doctordns
Copy link

What do $path and $commit contain?

@dolansgists
Copy link

dolansgists commented Jan 24, 2018

@doctordns

$path is the path to the file.
$commit is the value returned by the first command. More specifically it is the id of the commit where the file last existed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment