git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* rebasing a merge
@ 2010-06-17 15:51 Jay Soffian
  2010-06-18  4:38 ` Jay Soffian
  2010-06-18  9:10 ` Peter Krefting
  0 siblings, 2 replies; 6+ messages in thread
From: Jay Soffian @ 2010-06-17 15:51 UTC (permalink / raw)
  To: git

Say you have:

-o--o--o--m master
         /
--o--o--o   side

You're ready to push the merge, but in the mean time:

         o--o--o origin/master
        /
-o--o--o--m master
         /
--o--o--o   side

For various reasons, when this happens I want to rebase my merge (m).
It is almost always a merge that involves a fair amount of conflict
resolution. Here's how I've been doing it, but I'll bet there's a less
convoluted way:

git merge origin/master                      # resolve as needed
git branch -f temp                           # save the tree
git reset --hard ORIG_HEAD                   # restore back to the merge
git rebase -i -p --onto origin/master HEAD~1 # rebase the merge
git checkout temp -- .                       # resolve the conflict here
git rebase --continue                        # commit the resolution
git diff temp                                # no differences
git branch -D temp

Thoughts?

j.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: rebasing a merge
  2010-06-17 15:51 rebasing a merge Jay Soffian
@ 2010-06-18  4:38 ` Jay Soffian
  2010-06-18  9:10 ` Peter Krefting
  1 sibling, 0 replies; 6+ messages in thread
From: Jay Soffian @ 2010-06-18  4:38 UTC (permalink / raw)
  To: git

On Thu, Jun 17, 2010 at 11:51 AM, Jay Soffian <jaysoffian@gmail.com> wrote:
> git merge origin/master                      # resolve as needed
> git branch -f temp                           # save the tree
> git reset --hard ORIG_HEAD                   # restore back to the merge
> git rebase -i -p --onto origin/master HEAD~1 # rebase the merge
> git checkout temp -- .                       # resolve the conflict here
> git rebase --continue                        # commit the resolution
> git diff temp                                # no differences
> git branch -D temp

This is a bit more efficient:

mc=$(git rev-parse HEAD)
p1=$(git rev-parse origin)
p2=$(git rev-parse HEAD^2)
git merge origin || exit 0
tree=$(git log -1 HEAD --pretty=%T)
git reset --hard $(git cat-file commit $mc | sed '1,/^$/d' | git
commit-tree $tree -p $p1 -p $p2)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: rebasing a merge
  2010-06-17 15:51 rebasing a merge Jay Soffian
  2010-06-18  4:38 ` Jay Soffian
@ 2010-06-18  9:10 ` Peter Krefting
  2010-06-18 15:19   ` Jay Soffian
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Krefting @ 2010-06-18  9:10 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git

Jay Soffian:

> Here's how I've been doing it, but I'll bet there's a less convoluted way:

Do you have git-rerere enabled? I have found that to be a major timesaver 
for cases like these.

-- 
\\// Peter - http://www.softwolves.pp.se/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: rebasing a merge
  2010-06-18  9:10 ` Peter Krefting
@ 2010-06-18 15:19   ` Jay Soffian
  2010-06-24  9:16     ` Peter Krefting
  0 siblings, 1 reply; 6+ messages in thread
From: Jay Soffian @ 2010-06-18 15:19 UTC (permalink / raw)
  To: Peter Krefting; +Cc: git

On Fri, Jun 18, 2010 at 5:10 AM, Peter Krefting <peter@softwolves.pp.se> wrote:
> Jay Soffian:
>
>> Here's how I've been doing it, but I'll bet there's a less convoluted way:
>
> Do you have git-rerere enabled? I have found that to be a major timesaver
> for cases like these.

I'm familiar with rerere. The problem is that my original merge often
takes me several attempts to get correct, where each attempt I'm
amending the merge. So once the merge is finally correct, I need to
retrain rerere (see my earlier post to the list about this). Now at
that point, I could use "git rebase  -i -p --onto ..." to redo the
merge and let rerere take care of the conflict resolution.

Which is what I was doing. But it occurred to me that the final tree
that I want is the same as if I just do a second merge, save that off,
then redo my original merge and commit it with the second merge's
tree. This is also a lot faster (this repo is 1GB well packed composed
of 40k files) and I think less error prone.

j.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: rebasing a merge
  2010-06-18 15:19   ` Jay Soffian
@ 2010-06-24  9:16     ` Peter Krefting
  2010-06-24 14:22       ` Jay Soffian
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Krefting @ 2010-06-24  9:16 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git

Jay Soffian:

> I'm familiar with rerere.

Yes, of course, sorry for not recognizing your name :-)

> Which is what I was doing. But it occurred to me that the final tree
> that I want is the same as if I just do a second merge,

So, you want to just discard the change in the new commit on the branch you 
merged?

You could probably get off by "git cat-file" the commit object, changing the 
parent reference to point to the newly introduced commit while leaving the 
rest intact, and then "git hash-object" the new commit object, and then 
forward the branch head to that one.

-- 
\\// Peter - http://www.softwolves.pp.se/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: rebasing a merge
  2010-06-24  9:16     ` Peter Krefting
@ 2010-06-24 14:22       ` Jay Soffian
  0 siblings, 0 replies; 6+ messages in thread
From: Jay Soffian @ 2010-06-24 14:22 UTC (permalink / raw)
  To: Peter Krefting; +Cc: git

On Thu, Jun 24, 2010 at 5:16 AM, Peter Krefting <peter@softwolves.pp.se> wrote:
> You could probably get off by "git cat-file" the commit object, changing the
> parent reference to point to the newly introduced commit while leaving the
> rest intact, and then "git hash-object" the new commit object, and then
> forward the branch head to that one.

Did you miss my followup message?

http://article.gmane.org/gmane.comp.version-control.git/149335

j.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-06-24 14:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-17 15:51 rebasing a merge Jay Soffian
2010-06-18  4:38 ` Jay Soffian
2010-06-18  9:10 ` Peter Krefting
2010-06-18 15:19   ` Jay Soffian
2010-06-24  9:16     ` Peter Krefting
2010-06-24 14:22       ` Jay Soffian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).