[英]Git + Rails: How to restore files deleted with “git rm -r”?
I deleted my db folder in a rails application in with git rm -r 我用git rm -r删除了rails应用程序中的db文件夹
I've tried 我试过了
git reset HEAD
and 和
git reset --hard HEAD
but the migration files arent coming back. 但是迁移文件没有回来。 I tried commiting, then running the reset and still nothing.
我尝试提交,然后运行重置,但仍然没有。
What should I do? 我该怎么办?
You can checkout the file from the commit where it still exists. 您可以从仍然存在的提交中签出文件。 Here's how to do it.
这是怎么做的。
git checkout <commit where the file still exists> -- db
# Example:
git checkout 6936142 -- db
# This also works, but if you have a branch named the same as the file or path,
# it will throw an error.
git checkout 6936142 db
Try git reset --hard HEAD^1
(the commit just before HEAD). 尝试
git reset --hard HEAD^1
(HEAD之前的提交)。 Or you can get the hash of a previous known working commit with git log
, then git reset --hard <hash>
. 或者您可以使用
git log
获取先前已知工作提交的哈希值,然后使用git reset --hard <hash>
。
You can checkout individual files from your last commit or index. 您可以从上次提交或索引中签出单个文件。
git checkout db/*
checks out everything under db from the indexgit checkout db/*
从索引中git checkout db/*
下的所有内容
git checkout master db/*
checks out everything under db from the head of the master branchgit checkout master db/*
从master分支的头部git checkout master db/*
下的所有内容
you may be able to salvage most of your stuff that way 你可能能够以这种方式挽救你的大部分东西
read more: git help checkout
阅读更多:
git help checkout
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.