How to clean up unused side-branches in your commi

2019-04-30 00:16发布

How would you clean up unused side-branches in your commit trees (not real git branches)?

Example (tree, fake-commit-hash, commit message, optional [pointers]):

*    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

The path 0001, 0003, 0004, 0006 should stay untouched, but the commits 0002 and 0005 are not useful and aren't doing any good. How do you delete the commits 0002 and 0005?

1条回答
Bombasti
2楼-- · 2019-04-30 01:00

tarsius wrote in an answer to another question:

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

which clears the reflog and then cleans up the repository. Cleaning the reflog at first doesn't always work, because meaningles commits marked by the reflog are kept alive by git-gc as long as the reflog doesn't expire (which is 90 days by default).

After doing this all dangling commits are really gone, as far as I understood. So one should be sure that one really doesn't need all of them anymore. If one really wants to keep some of the dangling commits, one can:

git checkout <dangling_commit_id>
git branch <new_branch_name_of_your_choice>

or use git format-patch to store the whole commit in a text file.

查看更多
登录 后发表回答