文章目录
我们平时工作的时候,可能会误删某个文件或者文件夹,这时候就需要把它找回
- 当文件被删除后,可以通过
git status
查看文件状态
➜ git:(test) git status
On branch test
Your branch is up to date with 'origin/test'.Changes not staged for commit:(use "git add/rm <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)# deleted:后面就是被删除的文件路径deleted: README.mdno changes added to commit (use "git add" and/or "git commit -a")
- 如果已经
git add .
添加到暂存区了,则需要先将文件/文件夹回退,反之这一步可以省略
# git reset HEAD 后面接被删除的文件/文件夹路径
➜ git:(test) ✗ git reset HEAD README.md
Unstaged changes after reset:
D README.md
- 最后执行这一步就可以恢复被删除的文件或文件夹了
# git checkout 后面接被删除的文件/文件夹路径
➜ git:(test) ✗ git checkout README.md
Updated 1 path from the index