search
HomeDevelopment ToolsgitHow to restore deleted folder with git (steps)

In the process of using Git for version control, we sometimes make some mistakes, such as accidentally deleting or modifying a file or folder. When we discover this error, many people's first reaction is to feel anxious and helpless, not knowing what to do. In fact, Git has a very useful function that can help us recover deleted folders. Let’s explain how to operate it.

  1. Open Git Bash

First, open your Git Bash terminal window. Make sure you have entered the directory where your Git repository is located.

  1. View historical submission records

We need to view historical submission records and find the submission records of deleted folders. You can view historical commit records through the following command:

git log

After executing the above command, all commit records of the current branch will be displayed, and the latest commit record will be arranged in chronological order at the top. You can exit by pressing the Q key.

If there are multiple branches in the Git warehouse, you can use the following command to view the submission record of the specified branch:

git log 分支名
  1. Find the submission record of the deleted folder

After executing the git log command, you will see a series of commit record information, as follows:

commit 58107b68d9d338cf3e3dbefd3a8d0a45b9421da5
Author: your_name <your_email>
Date:   Mon Jul 5 09:11:50 2021 +0300

    Your commit message</your_email>

where 58107b68d9d338cf3e3dbefd3a8d0a45b9421da5 is the hash value of this submission, We need to find the commit record that deleted the folder.

If you know the name of the deleted folder, you can use the following command to find the commit record containing that folder:

git log --all -- 

For example, the path to the deleted folder is src /components, you can execute the following command:

git log --all -- src/components

If you do not know the name of the deleted folder, you can first view all submission records, and then choose to restore the correct version.

  1. Recover deleted folders

After finding the submission record of the deleted folder, you can restore the deleted folder through the following command:

git checkout  -- 

For example, if the commit hash value of the deleted folder is found to be 58107b68d9d338cf3e3dbefd3a8d0a45b9421da5, and the path of the deleted folder is src/components, you can execute the following command:

git checkout 58107b68d9d338cf3e3dbefd3a8d0a45b9421da5 -- src/components

After executing the above command, Git will restore the folder in the selected historical version to the current branch. Now, you can go back to your code editor and see if the restored folder exists.

Summary

With the above steps, you can simply restore a folder accidentally deleted in Git. Of course, if you have a complete backup, your best option is to restore the folder from the backup. When you perform Git recovery operations, be sure to use caution to avoid any unnecessary losses or errors.

The above is the detailed content of How to restore deleted folder with git (steps). For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Git vs. GitHub: Exploring Their RolesGit vs. GitHub: Exploring Their RolesApr 16, 2025 am 12:06 AM

Git and GitHub are different tools: Git is a distributed version control system for managing code versions and collaborative development; GitHub is an online platform based on Git, providing code hosting and collaboration tools. Git's main features include version management, branch management, and collaborative development, while GitHub provides code hosting, collaboration tools and social networking capabilities.

GitHub: A Hub for Open Source and Software DevelopmentGitHub: A Hub for Open Source and Software DevelopmentApr 15, 2025 am 12:10 AM

GitHub is a Git-based version control system hosting platform that provides version control, collaborative development and community communication functions. Using GitHub can improve development efficiency and code quality.

Git and GitHub: What's the Relationship?Git and GitHub: What's the Relationship?Apr 14, 2025 am 12:10 AM

Git and GitHub are different tools: Git is software for version control, and GitHub is an online platform based on Git. 1.Git allows you to track file changes and collaborative development. 2. GitHub provides code hosting and collaboration tools to enhance team development efficiency.

GitHub: The Platform for Developers and ProjectsGitHub: The Platform for Developers and ProjectsApr 13, 2025 am 12:01 AM

The core features of GitHub include version control, branch management, code review, issue tracking and project management. 1. Version control and branch management are based on Git, allowing tracking of code changes and experimental development. 2. Code review is implemented through PullRequest to improve code quality and team collaboration. 3. Issues tracking and project management are carried out through Issues and the project management board to improve project transparency and traceability.

GitHub in Action: Examples and Use CasesGitHub in Action: Examples and Use CasesApr 12, 2025 am 12:16 AM

GitHub is a powerful tool to improve the efficiency and quality of software development. 1) Version control: manage code changes through Git. 2) PullRequests: Conduct code review and improve code quality. 3) Issues: Track bugs and project progress. 4) GitHubActions: Automate the construction, testing and deployment process.

Git vs. GitHub: Version Control and Code HostingGit vs. GitHub: Version Control and Code HostingApr 11, 2025 am 11:33 AM

Git is a version control system, and GitHub is a Git-based code hosting platform. Git is used to manage code versions and supports local operations; GitHub provides online collaboration tools such as Issue tracking and PullRequest.

What is Git in simple words?What is Git in simple words?Apr 09, 2025 am 12:12 AM

Git is an open source distributed version control system that helps developers track file changes, work together and manage code versions. Its core functions include: 1) record code modifications, 2) fallback to previous versions, 3) collaborative development, and 4) create and manage branches for parallel development.

Is Git the same as GitHub?Is Git the same as GitHub?Apr 08, 2025 am 12:13 AM

Git and GitHub are not the same thing. Git is a version control system, and GitHub is a Git-based code hosting platform. Git is used to manage code versions, and GitHub provides an online collaboration environment.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.