Patricia Sauer - Authentic Programming

How to recover a deleted file | The Git Checkout Command

recovery written in capital letters

It might happen that you delete a file by accident. Git can help you to recover it.

Recover a local deletion

In case that the deletion is only locally and has not been committed, you can recover the file by using the checkout command:

git checkout -- fileToRecover

Recover a pushed deletion

In case that the deletion has been committed, you have to search for the commit where the deletion happened and then recover the file from that commit by using the checkout command:

git checkout commitHash -- fileToRecover

Reference

For full reference see Git checkout documentation.

Liked this article?

Buy Me A Coffee

© 2018 - 2024 Patricia Sauer