我使用 git rm -r 在 Rails 应用程序中删除了我的 db 文件夹
我试过了
git reset HEAD
和
git reset --hard HEAD
但迁移文件没有回来。我尝试提交,然后运行重置,但仍然没有。
我该怎么办?
您可以从仍然存在的提交中签出该文件。这是如何做到的。
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
尝试git reset --hard HEAD^1
(在 HEAD 之前的提交)。git log
或者,您可以使用, then获取先前已知的工作提交的哈希git reset --hard <hash>
。
您可以从上次提交或索引中检出单个文件。
git checkout db/*
从索引中检查 db 下的所有内容
git checkout master db/*
从 master 分支的头部检查 db 下的所有内容
你也许可以用这种方式挽救你的大部分东西
阅读更多:git help checkout