Skip to content

Instantly share code, notes, and snippets.

@RoelVdP
Forked from marioflores/new_gist_file
Created March 22, 2018 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoelVdP/df0f16c0ef83fef815c95ca7ee2416af to your computer and use it in GitHub Desktop.
Save RoelVdP/df0f16c0ef83fef815c95ca7ee2416af to your computer and use it in GitHub Desktop.
Restore files with Git
If the deletion has not been committed, the command below will restore the deleted file in the working tree.
$ git checkout -- <file>
You can get a list of all the deleted files in the working tree using the command below.
$ git ls-files --deleted
If the deletion has been committed, find the commit where it happened, then recover the file from this commit.
$ git rev-list -n 1 HEAD -- <file>
$ git checkout <commit>^ -- <file>
In case you are looking for the path of the file to recover, the following command will display a summary of all deleted files.
$ git log --diff-filter=D --summary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment