Retrieve missing files from remote repo?

风格不统一 提交于 2019-12-13 12:01:16

问题


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 remote?

Normally I would just do a git clone but it seems there should be a better way.


回答1:


git checkout .

How do I discard unstaged changes in Git?




回答2:


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.




回答3:


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.)



来源:https://stackoverflow.com/questions/9828076/retrieve-missing-files-from-remote-repo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!