git 如何将丢失的文件拉回我的分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9705626/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:12:00  来源:igfitidea点击:

How do I pull missing file back into my branch

gitgithubgit-pull

提问by feronovak

I have cloned git project into local git repository. Then I have done something nasty to one of the files and in that panic I deleted file physically from drive (rm style.css) and also removed it from git (git rm style.css).

我已将 git 项目克隆到本地 git 存储库中。然后我对其中一个文件做了一些令人讨厌的事情,在那次恐慌中,我从驱动器 ( rm style.css) 中物理删除了文件,并从 git ( git rm style.css) 中删除了它。

I want to get original style.cssback from origin to my dev branch. Unfortunately my git thinks it is up-to-date and wont do anything.

我想将原件style.css从原点返回到我的开发分支。不幸的是,我的 git 认为它是最新的并且不会做任何事情。

root@debian:~/project.me# git status
# On branch dev
nothing to commit (working directory clean)

root@debian:~/project.me# git pull origin dev
Password for 'https://[email protected]':
From https://github.com/somewhere/project.me
* branch            dev        -> FETCH_HEAD
Already up-to-date.

What do I need to do to tell git that I want to download original style.cssfile back into my dev branch?

我需要做什么才能告诉 git 我想将原始style.css文件下载回我的 dev 分支?

回答by CJlano

Use git checkout. In your case:

使用git checkout. 在你的情况下:

git checkout origin/master style.css

This command will update the requested file from the given branch (here the remote branch origin/master).

此命令将从给定的分支(此处为远程分支origin/master)更新请求的文件。

Hope this helps

希望这可以帮助

回答by neoneye

If you want to restore all the missing files from the local repository

如果要从本地存储库恢复所有丢失的文件

git checkout .

Warning: This method also restores all changed files and drops all the changes

警告:此方法还会恢复所有更改的文件并删除所有更改

回答by prime

Go to the location of style.css (may be app/css/ )using consoleotherwise there will be pathspec error.

使用控制台转到 style.css 的位置(可能是 app/css/ ),否则会出现 pathspec 错误。

then execute :

然后执行:

git checkout origin/master style.css

git checkout origin/master style.css

回答by noabody

I intentionally deleted some files from a clone --depth 1and this brought the main files, and submodule ones, back.

我故意从克隆中删除了一些文件--depth 1,这将主文件和子模块文件带回来。

git checkout . -f && git submodule update --checkout -f