【问题标题】:restore lost commit by a known folder name通过已知文件夹名称恢复丢失的提交
【发布时间】:2010-11-18 13:22:30
【问题描述】:

我不小心弄丢了一根树枝。我猜它在 reflog 列表中,但是很难检查其中的每一个。我记得在该分支中创建了一个文件夹,其中包含一些文件,因此应该可以通过查找影响该文件夹的所有丢失提交来找到我的分支。所以问题是:我怎样才能找到这些提交?

【问题讨论】:

    标签: git commit restore


    【解决方案1】:

    我应该只在 reflog 命令中指定路径。如果工作树中不存在路径,则在路径前使用“--”很重要

    git reflog -- path/to/the/affected/folder
    

    【讨论】:

    • 请注意,这显示的信息与git log -g path/to/it 相同。
    【解决方案2】:

    您可以通过 grep git lstree 的输出来查找分支中的提交:

    for ID in `git reflog | cut -d' ' -f1` # filter out the commit ID
    do
      # show the tree for each commit and grep for the file there
      git ls-tree -r $ID | grep file/name && echo "File is on $ID"
    done
    

    【讨论】:

      猜你喜欢
      • 2021-03-26
      • 2021-01-11
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 2012-07-13
      • 1970-01-01
      • 2020-11-14
      相关资源
      最近更新 更多