Say I\'m in a Git repository. I delete a file and commit that change. I continue working and make some more commits. Then, I find I need to restore that file.
I know
I had to restore a bunch of deleted files from a specific commit, and I managed it with two commands:
git show --diff-filter=D --summary --name-only --no-commit-id | xargs git checkout ^ --
git show --diff-filter=D --summary --name-only --no-commit-id | xargs git reset HEAD
(Note the trailing space on the end of each command.)
The files had been added to the .gitignore file and then cleared with git rm
. I needed to restore the files, but then unstage them. I had hundreds of files to restore, and typing things manually for each file as in the other examples was going to be far too slow.