All of lore.kernel.org
 help / color / mirror / Atom feed
* how to rebase backwards
@ 2009-11-03  5:45 bill lam
  2009-11-03  7:43 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: bill lam @ 2009-11-03  5:45 UTC (permalink / raw)
  To: git

I want to rebase a new branch onto an earlier commit 

original:  
E is a newly created branch from D and not yet modified
                    E
                   /
-- A -- B -- C -- D

new: what I wanted
     B'-- C' -- E     for deployment
    /          
-- A -- B -- C -- D    trunk

so that I can continue to change all commits from B to C without
affecting E

I try (not sure if correct) doing it by
  git rebase --onto A B E

but then there is a lot of conflict/both modified files. What will be
the correct way to do it?

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3

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

* Re: how to rebase backwards
  2009-11-03  5:45 how to rebase backwards bill lam
@ 2009-11-03  7:43 ` Junio C Hamano
  2009-11-03  9:37   ` bill lam
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2009-11-03  7:43 UTC (permalink / raw)
  To: bill lam; +Cc: git

bill lam <cbill.lam@gmail.com> writes:

> I want to rebase a new branch onto an earlier commit 
>
> original:  
> E is a newly created branch from D and not yet modified
>
>                     E
>                    /
> -- A -- B -- C -- D

I sense a grave misconception here.  If you have "not yet modified"
anything at all since D, then E does *not* even exist.

Remember, a branch is just a pointer pointing at a commit.  You can have
more than one such pointers pointing at the same commit.  So, if you have
been working on 'master' branch, building up to D, your history would look
like this:

    ---A---B---C---D
                   ^ master

And you would "create a branch", say "hack", like this:

    $ git checkout -b hack

What happens to your history when you do so is this:

                   v hack
    ---A---B---C---D
                   ^ master

The same commit "D", pointed by two branches, 'master' and 'hack'.

If you start editing files at this point, before making a commit, nothing
in the history changes.  But once you make a commit E while on branch
'hack' (since you ran "git checkout -b hack" above), the history changes
into this:

                     E
                    /^ hack
    ---A---B---C---D
                   ^ master

> new: what I wanted
>
>      B'-- C' -- E     for deployment
>     /          
> -- A -- B -- C -- D    trunk
>
> so that I can continue to change all commits from B to C without
> affecting E
>
> I try (not sure if correct) doing it by
>   git rebase --onto A B E

This asks to replay C, D and E in this order on top of A, to create

      C'--D'--E'
     /
 -- A

which is different from what you described earlier.

Assuming that you did actually commit to create E, after branching 'hack'
off of 'master', i.e. your history looks like this:

                     E
                    /^ hack
    ---A---B---C---D
                   ^ master

the way to create what you want would actually be

    $ git checkout -b deploy master^ ;# branch deploy at "C"
    $ git cherry-pick hack           ;# replay E on top of it

which would make a history of this shape.

                 v deploy
                 E'  E
                /   /^ hack
    ---A---B---C---D
                   ^ master

If you need to later tweak B and C (only) for deployment branch, you could
further rewrite B and/or C with

    $ git rebase -i A

to rewrite everything since A leading to the tip of your current branch
(i.e. E'), to result in

                   v deploy
           B'--C'--E"
          /
         /       E'  E
        /       /   /^ hack
    ---A---B---C---D
                   ^ master

Now, you may not want to keep both 'hack' and 'deploy'.  Perhaps you
forked 'deploy' and modified for E but it was done on top of D that you
did not want to include in 'deploy' by mistake.  IOW, you might have done
this:

                     E
                    /^ deploy
    ---A---B---C---D
                   ^ master

Another way to make 'deploy' point at the result of replaying E on top of
C when your history looks like this is (assuming you are on 'deploy'):

    $ git reset --hard HEAD^^ ;# reset to "C"
    $ git cherry-pick @{1}    ;# cherry-pick "E"

That would give you a history of this shape:

                 v deploy
                 E'  E
                /   /
    ---A---B---C---D
                   ^ master

Note that the original commit "E" becomes dangling and it will eventually
be garbage-collected.

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

* Re: how to rebase backwards
  2009-11-03  7:43 ` Junio C Hamano
@ 2009-11-03  9:37   ` bill lam
  2009-11-05 19:12     ` David Kågedal
  0 siblings, 1 reply; 5+ messages in thread
From: bill lam @ 2009-11-03  9:37 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: bill lam, git

Thank you for detail explanation.  From what you described, I begin
with master commit D, 
 $ git checkout -b deploy
 $ git commit --allow-empty -m deploy

 
                      E
                     /^ deploy
     ---A---B---C---D
                    ^ master
 
 $ git rebase -i A

                      v deploy
          B'--C'--D'--E'
         /
     ---A---B---C---D
                    ^ master

since E is an empty commit, I suppose content of D' E' and D are
identical at this point.  Is that correct?

If several months later, I forget which is the common ancestor for
master and deploy, how do I generate the above graph or identify
commit A as the common ancestor for these two branches?

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3

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

* Re: how to rebase backwards
  2009-11-03  9:37   ` bill lam
@ 2009-11-05 19:12     ` David Kågedal
  2009-11-06  1:43       ` bill lam
  0 siblings, 1 reply; 5+ messages in thread
From: David Kågedal @ 2009-11-05 19:12 UTC (permalink / raw)
  To: Junio C Hamano, git, bill lam

bill lam <cbill.lam@gmail.com> writes:

> Thank you for detail explanation.  From what you described, I begin
> with master commit D, 
>  $ git checkout -b deploy
>  $ git commit --allow-empty -m deploy

But why on earth would you want to use --allow-empty? There is no reason
for that. Just let deploy be where it is when you created it (until you
actually add something to it).

>                       E
>                      /^ deploy
>      ---A---B---C---D
>                     ^ master
>  
>  $ git rebase -i A
>
>                       v deploy
>           B'--C'--D'--E'
>          /
>      ---A---B---C---D
>                     ^ master
>
> since E is an empty commit, I suppose content of D' E' and D are
> identical at this point.  Is that correct?

Assuming you didn't intentionally change it during rebase, yes.

> If several months later, I forget which is the common ancestor for
> master and deploy, how do I generate the above graph or identify
> commit A as the common ancestor for these two branches?

That is exactly what git does all the time. You can use many
command. For instance git log --graph master...deply whill show you both
branches, starting from their common ancestor. "git merge-base deploy
master" will tell you that the common ancestor is. Etc.

-- 
David Kågedal

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

* Re: how to rebase backwards
  2009-11-05 19:12     ` David Kågedal
@ 2009-11-06  1:43       ` bill lam
  0 siblings, 0 replies; 5+ messages in thread
From: bill lam @ 2009-11-06  1:43 UTC (permalink / raw)
  To: David, =?iso-8859-1?Q?K=E5gedal_=3Cdavidk=40lysator=2Eliu=2Ese=3E?=
  Cc: Junio C Hamano, git

On Thu, 05 Nov 2009, David Kågedal wrote:
> command. For instance git log --graph master...deply whill show you both
> branches, starting from their common ancestor. "git merge-base deploy
> master" will tell you that the common ancestor is. Etc.

David, thank you for this info.

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3

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

end of thread, other threads:[~2009-11-06  1:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-03  5:45 how to rebase backwards bill lam
2009-11-03  7:43 ` Junio C Hamano
2009-11-03  9:37   ` bill lam
2009-11-05 19:12     ` David Kågedal
2009-11-06  1:43       ` bill lam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.