[英]Git - deleted some files locally, how do I get them from a remote repository
I've deleted some files on my PC, how do I download them again?我已经删除了我电脑上的一些文件,我如何重新下载它们?
Pull says: "Already up-to-date".拉说:“已经是最新的”。
Since git is a distributed VCS, your local repository contains all of the information.由于 git 是分布式 VCS,您的本地存储库包含所有信息。 No downloading is necessary;无需下载; you just need to extract the content you want from the repo at your fingertips.你只需要在你的指尖从 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,然后将其粘贴进去。
git checkout filename
git reset --hard
也可以解决问题
如果在本地删除了多个文件但没有提交,可以强制签出
$ git checkout -f HEAD
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 .有关更多详细信息,请查看文档。
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^
来检出最后的修订版。
这是一个相当小众的用例(虽然很有趣地回答了确切说明的问题),但以防万一有人需要这个:如果你执行git filter-branch
删除文件及其历史记录,然后你只想恢复删除文件的最新版本, git checkout filename
是不够的(因为该文件不再在存储库的本地历史记录中),您需要指定要使用git checkout origin/main -- filename
重置为远程版本git checkout origin/main -- filename
。
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!!我希望这可以帮到你!!
在代码目录中: git checkout .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.