如何清理提交树中未使用的侧枝?

时间:2012-08-01 09:21:07

标签: git git-rebase

如何清理提交树中未使用的侧枝(不是真正的git branch)?

示例(树,伪提交哈希,提交消息,可选[指针]):

*    0001 last commit [master] [origin/master] [HEAD]
| *  0002 old, unused merge
|/|
* |  0003 some remote commits
* |  0004 another commit from remote
| *  0005 old, unused commits
|/
*    0006 old tree

路径0001,0003,0004,0006应该保持不变,但是提交0002和0005没有用,并且没有任何好处。你如何删除提交0002和0005?

1 个答案:

答案 0 :(得分:9)

tarsius写了in an answer to another question

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

清除reflog,然后清理存储库。首先清理reflog并不总是有效,因为只要reflog没有到期(默认为90天),git-gc就会保留由reflog标记的意义​​提交。

据我所知,在这样做之后,所有悬挂的提交都真的消失了。所以应该确定一个人真的不再需要所有这些了。如果一个人真的想要保留一些悬空提交,可以:

git checkout <dangling_commit_id>
git branch <new_branch_name_of_your_choice>

或使用git format-patch将整个提交存储在文本文件中。

相关问题