如何删除不需要的git提交?

Chr*_*olf 11 git

我的git repositry中有一些垃圾提交.这些是由git gui在再次更改最新提交时创建的,并且意外地创建了其他提交.

现在我有一些提交,没有分配HEAD(分离,不是任何分支的一部分).

我想整理一下,我的问题是:如何删除这些提交(参见F,G和H)?这是使用rebase还是还原或重置?或者使用其他工具?我必须在哪个承诺上做这件事?

A -- B -- C -- D -- E [master]
      \-- F -- G
           \-- H
Run Code Online (Sandbox Code Playgroud)

谢谢

基督教

cdh*_*wie 17

试试这个:

git reflog expire --expire=now
git gc --prune=now
Run Code Online (Sandbox Code Playgroud)

  • 我不得不使用`--all`标志和`reflog`来修剪我的提交:`git reflog expire --expire = now --all`.另外,我发现`git fsck`命令对于查找正在发生的事情很有用; 特别是,`git fsck --unreachable --no-reflog`显示了无法访问或只能从reflog访问的提交. (10认同)

man*_*lds 6

执行以下操作:

git config gc.reflogexpireUnreachable now
git gc --prune=now
git config --unset gc.reflogexpireUnreachable
Run Code Online (Sandbox Code Playgroud)