【问题标题】:Git + Rails: How to restore files deleted with "git rm -r"?Git + Rails:如何恢复使用“git rm -r”删除的文件?
【发布时间】:2011-06-28 19:11:17
【问题描述】:

我使用 git rm -r 删除了 Rails 应用程序中的 db 文件夹

我试过了

git reset HEAD

git reset --hard HEAD

但是迁移文件没有回来。我尝试提交,然后运行重置,但仍然没有。

我该怎么办?

【问题讨论】:

标签: git git-rm


【解决方案1】:

试试git reset --hard HEAD^1(HEAD 之前的提交)。或者,您可以使用git loggit reset --hard <hash> 获取先前已知工作提交的哈希。

【讨论】:

    【解决方案2】:

    您可以从上次提交或索引中签出单个文件。

    git checkout db/* 从索引中检出 db 下的所有内容

    git checkout master db/* 从 master 分支的头部检查 db 下的所有内容

    这样你也许可以挽救你的大部分东西

    阅读更多:git help checkout

    【讨论】:

      【解决方案3】:

      您可以从仍然存在的提交中签出文件。以下是操作方法。

      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-02
        • 2011-01-08
        • 1970-01-01
        • 2012-08-24
        • 2016-07-09
        • 2023-03-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多