Jaw*_*wap 6 git branch commit git-rebase git-branch
我有这样的git提交历史记录:
U
/
A---B---C---D---E master
Run Code Online (Sandbox Code Playgroud)
没有什么指向提交U,但我知道它的哈希.如何从我的存储库中完全删除此提交,就好像它从未存在过一样?我是唯一一个使用这个回购的人.
我尝试使用git rebase,但是可以删除分支的部分或移动提交,但似乎无法删除单个提交.
如果我这样做git checkout <hash>,那么git reset --hard HEAD~1我就不再看到提交了.它实际上是完全消失还是仍然隐藏在回购中?
如上所述这里,只需使用
git reflog expire --expire-unreachable=now --all
git gc --prune=now
Run Code Online (Sandbox Code Playgroud)
git reflog expire --expire-unreachable=now --all删除所有无法访问的提交reflog.
git gc --prune=now 删除提交本身.
注意:只有使用git gc --prune=now才会起作用,因为这些提交仍在reflog中引用.因此,清除reflog是必需的.