Git - 在本地删除了一些文件,如何从远程存储库中获取它们
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4235431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git - deleted some files locally, how do I get them from a remote repository
提问by Dick Colt
I've deleted some files on my PC, how do I download them again?
我已经删除了我电脑上的一些文件,我如何重新下载它们?
Pull says: "Already up-to-date".
拉说:“已经是最新的”。
回答by Cascabel
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.
由于 git 是分布式 VCS,您的本地存储库包含所有信息。无需下载;你只需要在你的指尖从 repo 中提取你想要的内容。
If you haven't committed the deletion, just check out the files from your current commit:
如果您尚未提交删除操作,只需查看当前提交中的文件:
git checkout HEAD <path>
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^ <path>
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.
但如果它是在n
提交前提交的,请使用HEAD~n
,或者干脆启动gitk
,找到相应提交的 SHA1,然后将其粘贴进去。
回答by ?imon Tóth
git checkout filename
git checkout filename
git reset --hard
might do the trick as well
git reset --hard
也可以做到这一点
回答by Amit
If you have deleted multiple files locally but not committed, you can force checkout
如果在本地删除了多个文件但没有提交,可以强制签出
$ git checkout -f HEAD
回答by rzskhr
If you deleted multiple files locally and did not commit the changes, go to your local repository path, open the git shell and type.
如果您在本地删除了多个文件并且没有提交更改,请转到您的本地存储库路径,打开 git shell 并键入。
$ git checkout HEAD .
All the deleted files before the last commit will be recovered.
将恢复上次提交之前删除的所有文件。
Adding "." will recover all the deleted the files in the current repository, to their respective paths.
加“.” 将当前存储库中所有已删除的文件恢复到各自的路径。
For more details checkout the documentation.
有关更多详细信息,请查看文档。
回答by meagar
You need to check out a previous version from before you deleted the files. Try git checkout HEAD^
to checkout the last revision.
在删除文件之前,您需要检查以前的版本。尝试git checkout HEAD^
签出最后的修订版。
回答by Mona Wade
Also, I add to do the following steps so that the git repo would be correctly linked with the IDE:
此外,我添加执行以下步骤,以便 git repo 将正确链接到 IDE:
$ git reset <commit #>
$ git checkout <file/path>
I hope this was helpful!!
我希望这可以帮到你!!