Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clean up unused side-branches in your commit trees?

Tags:

git

git-rebase

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?

like image 889
erikbstack Avatar asked Aug 01 '12 09:08

erikbstack


1 Answers

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.

like image 180
erikbstack Avatar answered Oct 11 '22 19:10

erikbstack