简体   繁体   English

Git - 在本地删除了一些文件,如何从远程存储库中获取它们

[英]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.

相关问题 如何在本地和远程存储库中从Git中的版本删除文件而不删除它们 - How to remove files from versioning in Git without deleting them, both locally AND ON A REMOTE repository 本地忽略git文件,但不要从存储库中删除它们 - Ignore git files locally but do not remove them from the repository Git rebase 冲突:许多文件在本地删除,并在远程修改。 如何`git rm`所有这些? - Git rebase conflict: many files deleted locally, and modified on remote. How to `git rm` all of them? 从本地存储库中删除文件/文件夹后,如何从远程git存储库中获取文件/文件夹? - How to get files/folders from a remote git repository after we delete them from our local repository? 如何从远程git存储库恢复已删除的文件? - How to restore deleted files from remote git repository? 通过从远程存储库中获取数据然后提交来删除某些文件,现在想还原旧文件 - Deleted some files by fetching data from remote repository and then commiting them, now want to restore old files 如何从已删除的 Git 远程存储库中恢复 - how to recover from a Git remote repository deleted 如何创建一个Git远程存储库,该存储库会忽略原始存储库中的某些文件? - How do I create a Git remote repository that omits certain files from the original repository? 我如何从目标c的GIT存储库中获取文件? - How do i get files from a GIT repository in objective c? 如何使用GIT从远程获取所有已删除的本地文件 - How to get all deleted local files from remote using GIT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM