Retrieve missing files from remote repo?

前端 未结 3 979
被撕碎了的回忆
被撕碎了的回忆 2021-02-14 15:56

I accidentally deleted a few files from my local git repo.

I have not pushed this change to the remote.

Is there a easy way to get these files back from the remo

相关标签:
3条回答
  • 2021-02-14 16:21
    git checkout .
    

    How do I discard unstaged changes in Git?

    0 讨论(0)
  • 2021-02-14 16:36

    You should just be able to either revert the commit with the deletions, or reset HEAD to the commit before you did the deletes, depending on whether you want to keep the deletions in the history or not.

    Alternatively, if you haven't committed the deletes yet, you can just checkout the deleted files to restore them from your local repo.

    0 讨论(0)
  • 2021-02-14 16:46

    To discard all local changes, you can do:

    git checkout .
    

    To avoid losing local changes, do this instead:

    git ls-files -d -z | xargs -0 git checkout --
    

    (Taken from http://data.agaric.com/restore-locally-deleted-files-git They also suggest using git update -- . but that is not a valid git command.)

    0 讨论(0)
提交回复
热议问题