git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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?
Next: Junio C Hamano
Message 1 of 4 in “Removing useless merge commit with "filter-branch"”
  1. Anatol PomozovMar 8, 2012
  2. Junio C HamanoMar 8, 2012
  3. Anatol PomozovMar 13, 2012
  4. Anatol PomozovMar 29, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.