How to retrieve deleted files?

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):

  1. Find the commit hash where the files were last present. You can use:

    git log --oneline

    Look for the commit before the deletion.

  2. Restore the deleted file using the commit hash:

    git checkout <commit_hash> -- path/to/deleted_file

Using git restore (for newer versions of Git):

  1. Find the commit hash where the files were last present using:

    git log --oneline
  2. 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.

0 Comments

no data
Be the first to share your comment!