Git - deleted some files locally, how do I get them from a remote repository

前端 未结 6 1259
星月不相逢
星月不相逢 2020-12-22 20:42

I\'ve deleted some files on my PC, how do I download them again?

Pull says: \"Already up-to-date\".

6条回答
  •  太阳男子
    2020-12-22 20:59

    Since git is a distributed VCS, your local repository contains all of the information. No downloading is necessary; you just need to extract the content you want from the repo at your fingertips.

    If you haven't committed the deletion, just check out the files from your current commit:

    git checkout HEAD 
    

    If you have committed the deletion, you need to check out the files from a commit that has them. Presumably it would be the previous commit:

    git checkout HEAD^ 
    

    but if it's n commits ago, use HEAD~n, or simply fire up gitk, find the SHA1 of the appropriate commit, and paste it in.

提交回复
热议问题