问题描述
我必须从本地git存储库中删除最后5个提交,我是通过 reset --hard
到新的HEAD提交删除的:
I had to delete a the last 5 commits from a local git repo, I did so by reset --hard
to the new HEAD commit:
git reset --hard abcde1
现在,我需要从历史记录中删除那些未引用的提交,在这里阅读了许多答案之后,我尝试运行以下内容.
Now I need to remove those unreferenced commits from the history, after reading many answers here I tried running the following.
git gc --prune=now
和
git prune --expire=now --agressive
我找不到的答案似乎都对我有用,例如,我仍然可以看到带有 git show< sha>
的那些提交,我在这里遗漏了什么?是否可以从历史记录中完全删除提交?
None of the answers I found seem to work for me, for example I can still see a those commits with git show <sha>
, what am I missing here? Is possible to remove a commit from history completely?
最后,如果我将其推送到新的来源(比如说它是一个全新的仓库),那些未引用的提交也会被推送吗?
And finally, if I push to a new origin (let's say it's a completely new repo) are those unreferenced commits also pushed?
推荐答案
未引用或孤立的提交不会被推送到原始位置.这些提交将在某个时候被git的垃圾收集删除.如果要强制垃圾收集,请执行此操作
Unreferenced or orphaned commits will not be pushed to the origin. Those commits will be removed by git's garbage collection in sometime. Do this if you want to force the garbage collection
git config gc.reflogexpireUnreachable = now
git gc --prune=now
git config gc.reflogexpireUnreachable = "2 days"
这篇关于如何从git历史记录中完全删除提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!