还原git中的文件并将其从历史记录中删除

还原git中的文件并将其从历史记录中删除,git,Git,是否有一种方法可以从特定提交中还原文件,并从历史记录中删除曾经更改过的文件 例如,如果文件名为helpme.txt,并且提交为c5ggjj5。我如何将其恢复到更改前的状态,并使其从未显示在更改的历史记录中?可以这样做: git rebase -i c5ggjj5~ # the first revision should be the one you want to modify # mark that revision with edit or e # save and exit # rebas

是否有一种方法可以从特定提交中还原文件,并从历史记录中删除曾经更改过的文件


例如,如果文件名为
helpme.txt
,并且提交为
c5ggjj5
。我如何将其恢复到更改前的状态,并使其从未显示在更改的历史记录中?

可以这样做:

git rebase -i c5ggjj5~
# the first revision should be the one you want to modify
# mark that revision with edit or e
# save and exit
# rebase will start and will stop on that specific revision
git rm --cached helpme.txt #keeping it in the working tree, just in case
git commit --amend --no-edit
git rebase --continue

如果该文件没有被任何其他后续修订所触及,那么rebase应该可以正常运行警告:您正在重写有影响的历史记录。

它不会重新设置所有提交文件的基础吗?啊啊啊啊。。。。什么?Rebase将在您正在修改的版本之后重新应用所有修订,以便所有其他文件都将以原来的方式结束(在内容和历史方面)。。。明白你在改写历史,我现在明白了。感谢您的澄清。:)