Git恢复被意外删除为Commit的文件

   |   1 minute read   |   Using 80 words

Git恢复被意外删除为Commit的文件

场景

  • 已有git 仓库
  • 做了更改,没有提交,但 git 追踪到了
  • 意外删除了文件

    On branch main
    Your branch is up to date with 'origin/main'.
    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:    README.md
        deleted:    src/build.bash
        deleted:    src/images/test.png             
    
    

恢复所有文件

git restore --staged --worktree .

恢复某个文件

git restore src/build.bash

note: befor you do anything, backup a original verion , think twice, make sure you know what you are doing



© 2025 by clayliu. All Rights Reserved.