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

前端 未结 27 1671
挽巷
挽巷 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:09

    user@bsd:~/work/git$ rm slides.tex
    user@bsd:~/work/git$ git pull 
    Already up-to-date.
    user@bsd:~/work/git$ ls slides.tex
    ls: slides.tex: No such file or directory
    

    Restore the deleted file:

    user@bsd:~/work/git$ git checkout
    D       .slides.tex.swp
    D       slides.tex
    user@bsd:~/work/git$ git checkout slides.tex 
    user@bsd:~/work/git$ ls slides.tex
    slides.tex
    

提交回复
热议问题