简体   繁体   English

在保留历史记录的同时恢复git目录

[英]Restoring git directory while preserving history

I know that you can restore a previously removed directory as follows 我知道您可以按以下方式还原以前删除的目录

git checkout {revision} -- {dir}

However, the history of all files in the restored directory is completely gone. 但是,已还原目录中所有文件的历史记录已全部消失。 They are all seen as 'new' files. 它们都被视为“新”文件。

Is there a way to restore the directory while still preserving its files' history? 有没有一种方法可以在还原目录的同时仍保留其文件的历史记录?

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

I found this here 我在这里找到这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM