51

使用克里斯对另一个问题的回答,我可以将快照历史记录添加到我的 git 存储库中。由于其中一个文件不是我的历史记录的一部分,而是仅在快照中,因此第一个原始提交现在也包含该文件的删除。我该如何撤消呢?

起初我认为这与如何从 git 的历史记录中删除敏感文件相反,但实际上我不想将文件插入历史记录,而只是从历史记录中删除删除。

4

2 回答 2

71
git checkout <commit> <filename>
于 2010-06-30T14:53:01.680 回答
62

我知道了:

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

不幸的是,编辑这会将所有标签留在旧时间轴上,请参见此处

于 2010-06-30T15:03:53.997 回答