git > undo deletion by mistake

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!

Image for post

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>
Image for post

2. recover with git checkout

  • use the retrieved to recover file with git checkout
git checkout <sha> <filename>
Image for post
Image for post

Originally published at http://pavol.kutaj.com on August 8, 2020.

Written by

today I learnt… | as a support eng of the wonderful Snowplow Analytics, expect everything around modern (postmodern?) business intelligence

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store