How to find and restore a deleted file in a Git repository

前端 未结 27 1488
挽巷
挽巷 2020-11-22 01:25

Say I\'m in a Git repository. I delete a file and commit that change. I continue working and make some more commits. Then, I find I need to restore that file.

I know

27条回答
  •  轮回少年
    2020-11-22 02:08

    1. Use git log --diff-filter=D --summary to get all the commits which have deleted files and the files deleted;
    2. Use git checkout $commit~1 path/to/file.ext to restore the deleted file.

    Where $commit is the value of the commit you've found at step 1, e.g. e4cf499627

提交回复
热议问题