Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Introduction to Git Managing Committed Files Undoing File Deletions

how to retrieve file with git

How can I then retrieve a file that have been deleted and I have also deleted it using git with this comman git rm

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Need a little more detail to answer this question. Such as, when was this file deleted? Has the change been committed? If so, the file deletion commit was made how many commits ago?

But in any case, there's always one method you can use to retrieve the deleted file, by using git checkout commit hash ID.

First type in

git log

This will list all the past commits along w/ their commit hash ID, hash ID is a character strings looks sth like this 4a02b5fc3d9759ed8d3180b37cd982c8b30f8696.

Look through the commit history and find a commit prior to the file deletion, copy its commit hash ID, then enter this command.

git checkout 4a02b5fc3d9759ed8d3180b37cd982c8b30f8696

git will take you back to this particular commit and the deleted file is retrieved.

You are a life saver, Thank you so much