Removing useless merge commit with "filter-branch"
- From
Anatol Pomozov <anatol.pomozov@gmail.com>
- Date
- Mar 8, 2012, 23:21 UTC
- Message-ID
- <CAOMFOmWMsXgepY0-ZWFymd9uHSUmbOk66r75qa-Kv5TWx_U=EA@mail.gmail.com>
Hi,
I have a large project (~100K commits) and I need to split a part of it into separate project. What I usually do in this case is
git filter-branch --prune-empty --index-filter 'git rm -rfq --cached --ignore-unmatch UNNEEDED_DIRECTORIES' HEAD
that works more or less fine for me.
The original project has a lot of merge commits (don't ask me why). Basically every non-merge commit is merged back to master branch instead of rebasing on top of the master. In the command above I use --prune-empty parameter that removes empty commits, but not their merge points. This leaves a lot of "useless commit points" like this:
| o - merge commit that previously merged feature X |\ | \ | \ o | - real commit | | | / |/ |
As of me such merge left-overs are completely useless and I would like to remove them. Actually this task can be split into 2 steps: 1) Remove useless parents. A useless part is the one that points to a commit that is *already* reachable by some other parent. This step converts useless merge points to regular empty commits. 2) run filter branch with --prune-empty that removes such empty commits.
So my questions are: 1) What is the best way to remove "useless parents" as in the algorithm above? 2) Should such behavior (remove useless parent/merge commits) be enabled when flag --prune-empty is used?