To retrieve deleted files in Git, you can use the git checkout command or git restore command, depending on your Git version. Here are the steps:
Using git checkout (for older versions of Git):
-
Find the commit hash where the files were last present. You can use:
git log --onelineLook for the commit before the deletion.
-
Restore the deleted file using the commit hash:
git checkout <commit_hash> -- path/to/deleted_file
Using git restore (for newer versions of Git):
-
Find the commit hash where the files were last present using:
git log --oneline -
Restore the deleted file:
git restore --source <commit_hash> -- path/to/deleted_file
After restoring:
Once you have retrieved the files, you can add them back to the staging area and commit the changes:
git add path/to/deleted_file
git commit -m "Restored deleted files"
Make sure to replace <commit_hash> and path/to/deleted_file with the actual commit hash and file path you want to restore.
