threads / discuss / 23179

Rebasing with merges and conflict resolutions

Subject: Rebasing with merges and conflict resolutions

## tl;dr

5 messages between Mar 26, 2010 and Mar 26, 2010.

replies: 4people: 3as markdown or json

R. Tyler Ballance· Mar 26, 2010, 03:11 UTC · lore
I am trying to use rebase to straighten out a couple topic branches' histories
and running into nothing but troubles and I'm wondering if:
   a) I'm doing it wrong (highly likely)
   b) what I want is not possible
   c) banana!

Two contributors worked in tandem on a particular project, constantly merging back and forth between each other creating a history of 118 commits total with 37 of them being merge commits, 7 of those merge commits having conflict resolutions involved.

I would /like/ to rebase those into a more linear revision history, but I
can't seem to find any set of commands that doesn't have me:
   a) Manually re-doing every conflict resolution and merge (git rebase -p master)
   b) Drastically diverging from the original topic branch and entering some
      sort of mergeless hell (git rebase master)

Is it even possible to straighten this out without a massive rework of these commits?

In the future, is there a better way for two developers to work in the same back-and-forth fashion (code ping pong!) without leading to *heavily* merged histories that are unpossible to untangle?

Halp!
Cheers,
-R. Tyler Ballance
--------------------------------------
 Jabber: rtyler@jabber.org
 GitHub: http://github.com/rtyler
Twitter: http://twitter.com/agentdero
   Blog: http://unethicalblogger.com
Johannes Sixt· Mar 26, 2010, 07:02 UTC · re: R. Tyler Ballance · lore

Re: Rebasing with merges and conflict resolutions

Please don't set Mail-Followup-To on this list.
Am 3/26/2010 4:11, schrieb R. Tyler Ballance:
Show 10 quoted lines
> Two contributors worked in tandem on a particular project, constantly merging
> back and forth between each other creating a history of 118 commits total with
> 37 of them being merge commits, 7 of those merge commits having conflict
> resolutions involved.
> 
> I would /like/ to rebase those into a more linear revision history, but I
> can't seem to find any set of commands that doesn't have me:
>    a) Manually re-doing every conflict resolution and merge (git rebase -p master)
>    b) Drastically diverging from the original topic branch and entering some
>       sort of mergeless hell (git rebase master)

I'm afraid you can't avoid the merge conflict resolutions. But you can let you help by git-rerere. Look into the script rerere-train.sh that lets you prime your rerere database.

http://repo.or.cz/w/alt-git.git/blob_plain/master:/contrib/rerere-train.sh
> Is it even possible to straighten this out without a massive rework of these
> commits?

I would sort the commits into topics and then repeatedly rebase -i the history involved onto the same commit, each time removing those commits that do not belong to the topic. That is, you get a forest of topics sprouting from the same commit. Finally, merge the topics back together.

IOW, I wouldn't aim at a completely linear history, at least not at the first try.

> In the future, is there a better way for two developers to work in the same
> back-and-forth fashion (code ping pong!) without leading to *heavily* merged
> histories that are unpossible to untangle?

Discipline. Keep developers focused on their topic. Merge only after a topic is completed. Do not give in to "oh, *your* feature is cool, *I* want to have it now, so I merge it".

-- Hannes
R. Tyler Ballance· Mar 26, 2010, 17:16 UTC · re: Johannes Sixt · lore

Re: Rebasing with merges and conflict resolutions

On Fri, 26 Mar 2010, Johannes Sixt wrote:
Show 27 quoted lines
> Please don't set Mail-Followup-To on this list.
> 
> Am 3/26/2010 4:11, schrieb R. Tyler Ballance:
> > Two contributors worked in tandem on a particular project, constantly merging
> > back and forth between each other creating a history of 118 commits total with
> > 37 of them being merge commits, 7 of those merge commits having conflict
> > resolutions involved.
> > 
> > I would /like/ to rebase those into a more linear revision history, but I
> > can't seem to find any set of commands that doesn't have me:
> >    a) Manually re-doing every conflict resolution and merge (git rebase -p master)
> >    b) Drastically diverging from the original topic branch and entering some
> >       sort of mergeless hell (git rebase master)
> 
> I'm afraid you can't avoid the merge conflict resolutions. But you can let
> you help by git-rerere. Look into the script rerere-train.sh that lets you
> prime your rerere database.
> 
> http://repo.or.cz/w/alt-git.git/blob_plain/master:/contrib/rerere-train.sh
> 
> > Is it even possible to straighten this out without a massive rework of these
> > commits?
> 
> I would sort the commits into topics and then repeatedly rebase -i the
> history involved onto the same commit, each time removing those commits
> that do not belong to the topic. That is, you get a forest of topics
> sprouting from the same commit. Finally, merge the topics back together.

The problem I'm having with this is that with a `git rebase -p -i master` I can't even squash two related changes that are right next to each other together because the rebase bails out earlier on conflicts while trying to replay.

Perhaps I'm chosing the incorrect upstream?
Show 10 quoted lines
> IOW, I wouldn't aim at a completely linear history, at least not at the
> first try.
> 
> > In the future, is there a better way for two developers to work in the same
> > back-and-forth fashion (code ping pong!) without leading to *heavily* merged
> > histories that are unpossible to untangle?
> 
> Discipline. Keep developers focused on their topic. Merge only after a
> topic is completed. Do not give in to "oh, *your* feature is cool, *I*
> want to have it now, so I merge it".

I think that's easier said than done, with backend work I'm able to clearly define topics, whereas the front-end developers (as it is in this case) typically overlap ever so slightly in their work

Cheers,
-R. Tyler Ballance
--------------------------------------
 Jabber: rtyler@jabber.org
 GitHub: http://github.com/rtyler
Twitter: http://twitter.com/agentdero
   Blog: http://unethicalblogger.com
Jon Seymour· Mar 26, 2010, 18:11 UTC · re: R. Tyler Ballance · lore

Re: Rebasing with merges and conflict resolutions

Show 12 quoted lines
> > > In the future, is there a better way for two developers to work in the same
> > > back-and-forth fashion (code ping pong!) without leading to *heavily* merged
> > > histories that are unpossible to untangle?
> >
> > Discipline. Keep developers focused on their topic. Merge only after a
> > topic is completed. Do not give in to "oh, *your* feature is cool, *I*
> > want to have it now, so I merge it".
>
> I think that's easier said than done, with backend work I'm able to clearly
> define topics, whereas the front-end developers (as it is in this case)
> typically overlap ever so slightly in their work
>

If two developers are working together, then set them up so that each has a public and private repo.

The rule should be:
1. before publishing, A fetches from B to ensure that A has B's latest
public tip
2. A confirms that B's tip includes A's public tip
3. A rebases own private changes (between A public and A private) onto
B's public tip
4. A pushes her rebased private tip to her own public repo
5. B then repeats the cycle with the roles reversed.

This will work provided that B doesn't republish after 2 and before 4, so does require that A and B talk to each other before performing step 4.

jon.
Jon Seymour· Mar 26, 2010, 17:36 UTC · re: R. Tyler Ballance · lore

Re: Rebasing with merges and conflict resolutions

You might find this post from a few weeks back interesting:
    http://permalink.gmane.org/gmane.comp.version-control.git/140510

Unfortunately, I haven't had time to reproduce a robust implementation of the ideas, but I have exercised the algorithm manually a few times and it works quite well.

The basic idea is that you split the merge history into segments (where a segment is a single linear series of commits). Then starting from the oldest you rewrite:

A----B---M
  \---C---/
as:
A---B---e---C'---e'---M'

where e is a compensation that allows e to be automatically rebased onto B without merge conflicts and e' restores the tree to the point it was an M so that tree(M) and tree(M') are identical. See the original post for working out how to construct e and e'. The basic idea is you find the confllcts that would result if you attempted rebase C on B, then reset part of the tree in such a way that the conflicts are removed. e' then is the patch that restores tree(C') to tree(M)

You have to realise that the trees between e and e' will be inconsistent because part of the tree is shifted back in time in order to allow the C to rebase cleanly.

Once the history is linearised in this way, it is often (but not always) possible to reorder and then squash the commits in e --- C' --- e' such away that the consistency of the tree in this region is restored.

if you repeat this algorithm recursively for each merge in the merge history you can flatten the entire merge history out into a linear series of commits. This can be complete and automatic, alhough to obtain completeness you do lose consistency at certain well-delimited points in the history. Consistency can be restored, if required, by manually rebasing the linearised history in a single pass at the end.

I do intend to commit the algorithm to code at some point, but haven't had a chance to do so yet. See ( http://github.com/jonseymour/hammer) for a readme that also describes the idea in more detail

jon.
On Fri, Mar 26, 2010 at 2:11 PM, R. Tyler Ballance <tyler@monkeypox.org> wrote:
Show 38 quoted lines
> I am trying to use rebase to straighten out a couple topic branches' histories
> and running into nothing but troubles and I'm wondering if:
>   a) I'm doing it wrong (highly likely)
>   b) what I want is not possible
>   c) banana!
>
> Two contributors worked in tandem on a particular project, constantly merging
> back and forth between each other creating a history of 118 commits total with
> 37 of them being merge commits, 7 of those merge commits having conflict
> resolutions involved.
>
> I would /like/ to rebase those into a more linear revision history, but I
> can't seem to find any set of commands that doesn't have me:
>   a) Manually re-doing every conflict resolution and merge (git rebase -p master)
>   b) Drastically diverging from the original topic branch and entering some
>      sort of mergeless hell (git rebase master)
>
>
> Is it even possible to straighten this out without a massive rework of these
> commits?
>
> In the future, is there a better way for two developers to work in the same
> back-and-forth fashion (code ping pong!) without leading to *heavily* merged
> histories that are unpossible to untangle?
>
>
> Halp!
>
>
> Cheers,
> -R. Tyler Ballance
> --------------------------------------
>  Jabber: rtyler@jabber.org
>  GitHub: http://github.com/rtyler
> Twitter: http://twitter.com/agentdero
>   Blog: http://unethicalblogger.com
>
>

← back to recent threads