git: how to restore a file that has been deleted?

This question already has an answer here:

  • Find and restore a deleted file in a Git repository 19 answers

  • If change is commited:

    git checkout <commit hash> <filename>
    

    If change is not committed, see answer of WeGi.

    Also consider possibility of reverting the commit that deletes the file using git-revert, eg

    git revert <commit hash>
    

    git checkout filename should restore the file, if the change is uncommited.

    Also just found the question has allready been asked: Find and restore a deleted file in a Git repository

    链接地址: http://www.djcxy.com/p/18934.html

    上一篇: 如何恢复由提交删除的文件?

    下一篇: git:如何恢复已被删除的文件?