Tuesday, July 21, 2015

Retrieve a file that is mistakenly deleted with Git

Firstly, check the commits:

As-MacBook-Pro:Events aselims$ git log
commit dd2f0f7c2b3024ec29c2337be2f0a768a743a9a1
Author: aselims <selim.2k@gmail.com>
Date:   Tue Jul 14 20:22:15 2015 +0200

    time format.

commit 43032e348bf0015759836c4e5e035d66c62d05f1
Author: aselims <selim.2k@gmail.com>
Date:   Tue Jul 14 19:37:09 2015 +0200

    webFragment for support.
...

Then checkout the file you need from a specific revision
git checkout <revision> -- <path_to_file>

git checkout 43032e348bf0015759836c4e5e035d66c62d05f1 -- ./app/src/main/java/co/rahala/selim/events/util/WebFragment.java

The file is already now at its original place.