Introduction
As a developer, you might encounter situations where important files are accidentally deleted and committed. This challenge simulates such a scenario, testing your ability to use Git's history inspection and state restoration tools to recover lost files and restore your project to a working state.
Recover the Lost Files
Before starting this challenge, a Git repository has been initialized for you in the ~/project/important-project directory. This repository contains several commits, including the creation and subsequent accidental deletion of two important files. Here's what you need to know:
- The repository was created with an initial commit adding a
README.mdfile. - Two crucial files,
important_algorithm.pyandcrucial_data.txt, were added in a subsequent commit. - There were a few more commits with various changes.
- At some point,
important_algorithm.pyandcrucial_data.txtwere accidentally deleted, and this deletion was committed. - There has been at least one more commit after the accidental deletion.
Your task is to recover the deleted files by navigating the repository's history and then commit the recovered files.
Tasks
- Investigate the repository's history to find when
important_algorithm.pyandcrucial_data.txtwere deleted. - Restore the repository to the state just before the deletion.
- Keep the original commits and create a new commit with the message "Recover deleted files".
Requirements
- Work in the
~/project/important-projectdirectory. - Ensure
important_algorithm.pyandcrucial_data.txtare present after recovery. - Make sure the last commit message is "Recover deleted files", and the commit history is preserved.
Example
After successfully completing the challenge, running ls in the project directory should show:
$ ls ~/project/important-project
important_algorithm.py crucial_data.txt README.md
Running git status should show a clean working directory:
$ git status
On branch master
nothing to commit, working tree clean
And git log should show your new commit at the top:
$ git log --oneline
8876d8b (HEAD -> master) Recover deleted files
9b3525c Update project status
5e6234c Oops, accidentally deleted important files
9de9506 Update algorithm TODO
01c36ae Add crucial data and algorithm
638a98d Initial commit
Summary
In this challenge, you faced a common Git scenario: accidentally deleted files. You learned how to:
- Inspect your repository's complete history, including actions that changed the HEAD.
- Restore your repository to a specific previous state, effectively "turning back time" in your project.
- Create a new commit to save the restored state of your project.
These skills are invaluable for finding lost commits, undoing mistakes, and maintaining a clear project history. Remember, while these tools can save you from disaster, it's always best to work carefully and make frequent, well-documented commits to avoid such situations in the first place.
By completing this challenge, you've gained practical experience with some of Git's most powerful recovery tools, skills that will serve you well throughout your development career.



