Home  >  Article  >  Development Tools  >  Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

WBOY
WBOYforward
2022-03-31 19:04:374592browse

This article brings you relevant knowledge about Git, which mainly introduces issues related to git recovery of deleted files, including deletion operations submitted to the local library, deletion operations added When it comes to the temporary storage area, the deletion operation is all related to the work area. I hope it will be helpful to everyone.

Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

Recommended study: "Git Tutorial"

1. A few words before recovery

So-called use git command to restore deleted files, provided that the file needs to be managed by git.
In other words, this file has been submitted to the repository before.
This is a basic condition.
If this file is not managed by git, deleting it is the same as deleting an ordinary file on the computer.
[Core]: The core idea of ​​file recovery is: reset the workspace state to be consistent with the state of the version where the corresponding file exists, and the file will be back.
[Key points] Understanding the git reset --hard command

2. Scenario 1: The deletion operation is submitted to the local library

情景解释 : 工作区中删除一个文件,git add 到暂存区,git commit 提交版本库

1. Check the working directory and status

Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

2. Delete the file, add it to the staging area, and submit Go to the repository

Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

3. View the file directory of the workspace

Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

4. Revert to the previous version of the file and view the files in the workspace

Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

3. Scenario 2: The deletion operation is added to the staging area

情景解释 :工作区中删除一个文件,git add 到暂存区

1. Check the working directory and status

Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

2. Delete the file and add it to the temporary storage area

Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

3. View the file directory of the workspace

Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

4 .Restore to the version where the file existed before and view the file in the workspace

Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

4. Scenario 3: The deletion operation is only in the workspace

情景解释 : 工作区中删除一个文件

1. View the working directory and status

Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

2. Delete files, only delete files in the workspace
3. View the file directory of the workspace

Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

4. Restore to the version where the file existed before and view the files of the workspace
[Below Both methods are ok. It is recommended to use the method in Figure 2, which is also the method recommended by git】

Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)
Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples)

Recommended study: " Git tutorial

The above is the detailed content of Detailed explanation of Git basics: git recovery of deleted files (detailed explanation with examples). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete