Find Lost Files

Beginner

This tutorial is from open-source community. Access the source code

Introduction

Git is a powerful version control system that allows developers to track changes to their codebase. However, sometimes files can become lost or accidentally deleted. In this challenge, you will learn how to use Git to find lost files and commits.

This is a Challenge, which differs from a Guided Lab in that you need to try to complete the challenge task independently, rather than following the steps of a lab to learn. Challenges are usually a bit difficult. If you find it difficult, you can discuss with Labby or check the solution. Historical data shows that this is a beginner level challenge with a 97% pass rate. It has received a 100% positive review rate from learners.

Find Lost Files

You have been working on a project in the git-playground repository. However, you have noticed that some files are missing and you are not sure when they were deleted or how to recover them. Your task is to use Git to find any lost files and commits in the repository.

Tasks

  1. Navigate to the directory and configure the identity.
  2. Create and switch a branch named one-branch, delete file2.txt and commit with the message "Remove file2".
  3. Switch back to the master branch and delete the one-branch branch.
  4. Find any lost files and commits.
  5. Check the .git/lost-found directory to see if any lost files were recovered.
  6. If any lost files were found, review them to determine if they are the missing files.

This is the result of running the ls .git/lost-found command:

commit

Summary

Using Git to find lost files and commits can be a lifesaver when working on a project. By running the git fsck --lost-found command, you can identify any dangling objects and extract them into the .git/lost-found directory. From there, you can review the files to determine if they are the missing files.