git > undo deletion by mistake
2 min readAug 8, 2020
use-case
The concern is documenting the immediate recovery of the file deleted by mistake in the working area. Give me back the last commit!
1. get sha with git lot -full-history -all
- use the following the get the SHA of the requested commit
- it also gives the author/timestamp of the commit (version to be recovered)
git log --pretty=format:\"%C(auto)%h%d%Creset %C(cyan)(%ci)%Creset %C(green)%cn <%ce>%Creset %s\" --name-status --date=short --all --full-history -- <file-name>
2. recover with git checkout
- use the retrieved to recover file with
git checkout
git checkout <sha> <filename>
Originally published at http://pavol.kutaj.com on August 8, 2020.