2010-06-30 163 views
40

在另一个问题上使用Chris's answer我可以在我的git存储库中添加快照历史记录。由于其中一个文件不是我的历史记录的一部分,但仅在快照中,第一个原始提交现在还包含删除此文件。我怎样才能解开这个问题?如何取消删除以前在git历史记录中删除的文件?

起初我以为这是How do I remove sensitive files from git’s history的相反,但实际上我不想插入一个文件到历史记录中,只是从历史中删除删除。

+1

Git不会跟踪意向,只是内容。如果文件存在于祖先中,并且在子提交中被删除,那么“删除历史记录中的删除”和“重新插入历史记录”的含义相同:确保文件显示在子代及其子代中。 – 2010-06-30 20:10:19

回答

42

我懂了:

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> # thanks for reminding, kubi 
git commit --amend 
git rebase --continue 
git tag -d originalHead 

编辑不幸的是这将会使所有的标签在老时间表,看到here

+2

+1用于回答一个看似不可能的问题。哇。 – hobs 2012-06-24 01:39:11

68
git checkout <commit> <filename> 
+9

谢谢,但那只能恢复它。我希望历史看起来好像文件从未被删除 – 2010-06-30 14:59:12

相关问题