Remove an unreferenced commit from git repository

后端 未结 2 1488
我在风中等你
我在风中等你 2021-01-01 01:35

I have a git commit history like this:

          U
         / 
A---B---C---D---E master

Nothing points to the commit U, but I

相关标签:
2条回答
  • 2021-01-01 01:54

    Eventually it will be cleaned up by git, but you can look into git gc to actually force a garbage collect.

    The clean command is different and won't take care of this for you.

    0 讨论(0)
  • 2021-01-01 02:06

    As described here, simply use

    git reflog expire --expire-unreachable=now --all
    git gc --prune=now
    

    git reflog expire --expire-unreachable=now --all removes all references of unreachable commits in reflog.

    git gc --prune=now removes the commits themselves.

    Attention: Only using git gc --prune=now will not work since those commits are still referenced in the reflog. Therefore, clearing the reflog is mandatory.

    0 讨论(0)
提交回复
热议问题