【问题标题】:Restoring git directory while preserving history在保留历史记录的同时恢复 git 目录
【发布时间】:2015-05-15 07:20:22
【问题描述】:

我知道您可以按如下方式恢复以前删除的目录

git checkout {revision} -- {dir}

但是,已恢复目录中所有文件的历史记录已完全消失。它们都被视为“新”文件。

有没有办法恢复目录,同时仍保留其文件的历史记录?

【问题讨论】:

  • 你必须明确你想要什么......你想探索历史,然后回到你的分支提示吗?完全丢弃最近的历史,就好像它从未存在过一样?保留历史记录,但添加一个恢复旧状态的新提交?

标签: git restore


【解决方案1】:
git tag originalHead # just in case
git rebase -i <id of the parent of the commit that deleted the file>
# change pick to edit for that commit
git checkout <id of the previous commit> <filename>
git commit --amend
git rebase --continue
git tag -d originalHead

我找到了这个here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 2011-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多