【问题标题】:After committing, resetting head and then checking out the commit, git does not restore removed files提交后,重置头部然后签出提交,git不会恢复删除的文件
【发布时间】:2019-12-22 22:12:51
【问题描述】:

提交更改后,我错误地运行了git reset --hard HEAD^,这导致我丢失了提交更改中的文件。

我正在尝试恢复这些文件。

当我执行git reflog 时,它显示之前的提交thatCommit,所以我继续:

git checkout thatCommit

但是,没有文件被恢复。

当我输入 git checkout 时,它会打印出所有已删除的文件:

D path/to/deletedFile1
D path/to/deletedFile2
M path/to/changedFile1
M path/to/changedFile2

我希望恢复已删除的文件和更改的文件,但在我的仓库/分支中看不到 path/to/deletedFile1

如何恢复这些文件?

【问题讨论】:

    标签: git git-checkout git-reset


    【解决方案1】:

    试试

    git checkout thatCommit -- .
    

    (强制工作树重新初始化为该提交内容)

    或者:

    git reset --hard thatCommit
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-04
      • 2017-12-19
      • 1970-01-01
      • 1970-01-01
      • 2013-11-22
      • 1970-01-01
      • 2012-08-11
      相关资源
      最近更新 更多