【问题标题】:git: how to restore a file that has been deleted? [duplicate]git:如何恢复已删除的文件? [复制]
【发布时间】:2014-02-03 17:25:28
【问题描述】:

这是最新的差异

diff --git a/app/config/parameters.yml b/app/config/parameters.yml
deleted file mode 100755
index [not important]
--- a/app/config/parameters.yml
+++ /dev/null

附上评论:git log:

commit [not important]
Author: <not important>
Date:   [not important]

    Never commit the parameters.yml

现在 git 已经删除了这个文件,这破坏了整个网站。如何恢复?

这不是重复的,因为如果我这样做:

>git checkout [rev number not ipmortant] -- app/config/parameters.yml
error: pathspec 'app/config/parameters.yml' did not match any file(s) known to git.

那么它是怎么出现在历史上的的?

【问题讨论】:

    标签: git version-control


    【解决方案1】:

    如果提交更改:

    git checkout <commit hash> <filename>
    

    如果未提交更改,请参阅answer of WeGi。

    还要考虑使用 git-revert 恢复删除文件的提交的可能性,例如

    git revert <commit hash>
    

    【讨论】:

      【解决方案2】:

      git checkout filename 应该恢复文件,如果更改未提交。

      还发现问题已经被问到: Find and restore a deleted file in a Git repository

      【讨论】:

        猜你喜欢
        • 2020-09-11
        • 2020-07-09
        • 1970-01-01
        • 2017-05-10
        • 1970-01-01
        • 2010-12-23
        • 1970-01-01
        • 2019-08-26
        相关资源
        最近更新 更多