问题
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