Re: Removing useless merge commit with "filter-branch"
- From
Anatol Pomozov <anatol.pomozov@gmail.com>
- Date
- Mar 13, 2012, 22:27 UTC
- Message-ID
- <CAOMFOmUT+2q7jC9Z1=zFJdBi_KAg=A66yHJNF2LRvjfQcgbdFw@mail.gmail.com>
- In-Reply-To
- <7v62eebri3.fsf@alter.siamese.dyndns.org>
Hi
On Thu, Mar 8, 2012 at 3:30 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 38 quoted lines
> Anatol Pomozov <anatol.pomozov@gmail.com> writes: > >> | >> o - merge commit that previously merged feature X >> |\ >> | \ >> | \ >> o | - real commit >> | | >> | / >> |/ >> | > > It is unclear how many commits are drawn in the above picture and > what "feature X" is about in the above picture. Care to redraw the > commit DAG to explain what you are trying to do a bit better? > > The way I read it is that you start from a history like this (note > that when we draw an ascii art history we often write it sideways, > time flows from left to right): > > ---A-----B-----M--- > \ / > C-------D > > where a side branch to implement "feature X" that has C and D forked > at A, and it was merged at M after somebody else committed B on the > mainline. When you filtered out some parts of the tree, it turns > out that C and D are totally unintereseting because their changes > touch parts outside of your interest, i.e. the history is: > > ---A-----B-----M--- > \ / > o-------o > > where 'o' are now no-op. > > Is that what you are talking about?
Yes, in fact --prune-empty flag removes empty commits so the history looks like
-----A-------B-------M--------
\ /
--------------So M is a merge that has 2 parents A and B. I would like to remove this merge M and leave the history as
-----A-----B-----
as only these commits have changes in my library that I am trying to extract.
I think some trickery with "git filter-branch --parent-filter" should help here.
First one runs filter-branch with --parent-filter and removes useless parents from merges (in this example with will be parent A---M), this converts such merges to regular empty commits
then run filter-branch one more time with --prune-empty - it removes empty commits.
> > I think "log --simplify-merges A..M -- path" may already has logic > that deals with this, so it may help if you study what it does and > how it does what it does.