如何使用 git pull 取回已删除的文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38029810/
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
How to get deleted files back with git pull?
提问by vico
I had up to date repository. Then I had deleted several files and this was mistake. I would like to get fresh repository back. I do
我有最新的存储库。然后我删除了几个文件,这是错误的。我想取回新的存储库。我愿意
$ git pull origin master
And expect to get everything from server, but getting message that everything is up to date.
并期望从服务器获取所有内容,但收到所有内容都是最新的消息。
How to get my sources from server using git pull
then?
如何使用git pull
然后从服务器获取我的资源?
回答by Jeff Puckett
You can reset local branch to what's at remote
您可以将本地分支重置为远程分支
git reset --hard origin/master
回答by Harald Nordgren
The files are in your local git history so you won't need to pull code to get them back. Run
这些文件位于您本地的 git 历史记录中,因此您无需提取代码即可将其取回。跑
git checkout <file>
on the missing files. If you don't have any uncommited changes then
关于丢失的文件。如果您没有任何未提交的更改,则
git checkout .
in the git root directory will work as well.
在 git 根目录中也可以使用。
回答by Manjunatha S M
This shows all the deleted files.
这将显示所有已删除的文件。
git ls-files --deleted
This will restore the deleted file.
这将恢复已删除的文件。
git checkout <deleted file name with complete path>
回答by barden
What is the result of git status
command ?
You can also try git reset --hard origin/master
git status
命令的结果是什么?你也可以试试git reset --hard origin/master
回答by Shravan40
For all the unstaged files use
对于所有未暂存的文件,请使用
git checkout -- .
git checkout -- .
Or the more safer way
或者更安全的方式
git clean -fd
git clean -fd
回答by Maksym Semenykhin
thats all you need
这就是你所需要的
git reset --hard
git fetch origin
git pull origin master
回答by LoanJ4490
What about git stash command ?
If you didn't commit your changes (e.g the files deletions) then you can just run git stash
git stash 命令呢?如果您没有提交更改(例如文件删除),那么您可以运行git stash