2010-06-30 161 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

相關問題