# Need some help with git rebase

7 messages from 2009-12-28 to 2009-12-31. Participants: Sylvain RABOT, Sylvain Rabot, Wincent Colaiuta, Tay Ray Chuan, Peter Baumann.
Thread: https://gitlist.dev/t/22037

## Sylvain RABOT, 2009-12-28 13:33

Subject: Need some help with git rebase
Message-ID: <4B38B3A7.6010900@steek.com>
URL: https://gitlist.dev/e/4B38B3A7.6010900%40steek.com

```
Hello everybody,

I'm trying to backport a feature branch which is based on the master 
branch into another branch also based on master but older :

                         a--a--a--a--a--a--a--a--a feature
                        /
--x--x--x--x--x--x--x--x--x--x--x--x master
   \
    o--o--o--o--o--o--o 12.72.1
   
   
This is what I would like :
   
   
                         a--a--a--a--a--a--a--a--a feature
                        /
--x--x--x--x--x--x--x--x--x--x--x--x master
   \
    o--o--o--o--o--o--o--a--a--a--a--a--a--a--a--a 12.72.1
   

And this is what I get with git rebase --onto 12.72.1 master feature
   
    o--o--o--o--o--o--o--a--a--a--a--a--a--a--a--a feature
   /
--x--x--x--x--x--x--x--x--x--x--x--x master
   \
    o--o--o--o--o--o--o--a--a--a--a--a--a--a--a--a 12.72.1

Can you exlain to me what I need to do to get what I expect.

Best regards.

-- 
Sylvain

```

## Sylvain Rabot, 2009-12-30 22:24

Subject: Re: Need some help with git rebase
Message-ID: <1262211866.7068.1.camel@kheops>
URL: https://gitlist.dev/e/1262211866.7068.1.camel%40kheops
In-Reply-To: <4B38B3A7.6010900@steek.com>

```
So,

I tried again "git rebase --onto 12.72.1 master feature".

Situation :

                         a--a--a--a--a--a--a--a--a feature
                        /
--x--x--x--x--x--x--x--x--x--x--x--x master
   \
    o--o--o--o--o--o--o 12.72.1


Work flow :

$ git checkout 12.72.1
$ git rebase --onto 12.72.1 master feature

a lot of conflicts, resolving and git rebase --continue

And then, at the end of the rebase, without me doing anything, feature
branch is checked out and it seems that its HEAD has been reset to the
new 12.72.1 HEAD.

--x--x--x--x--x--x--x--x--x--x--x--x master
   \
    o--o--o--o--o--o--o--a--a--a--a--a--a--a--a--a 12.72.1 feature

Is that normal ? If it is, how do I do to avoid my feature branch to be
reset at 12.72.1's HEAD ?

Any enlightenment is very welcome.

Regards.

-- 
Sylvain Rabot <sylvain@abstraction.fr>

```

## Wincent Colaiuta, 2009-12-30 22:46

Subject: Re: Need some help with git rebase
Message-ID: <CB5B49CA-0C66-4384-9B47-3675E517E203@wincent.com>
URL: https://gitlist.dev/e/CB5B49CA-0C66-4384-9B47-3675E517E203%40wincent.com
In-Reply-To: <1262211866.7068.1.camel@kheops>

```
El 30/12/2009, a las 23:24, Sylvain Rabot escribió:

> So,
>
> I tried again "git rebase --onto 12.72.1 master feature".
>
> Situation :
>
>                         a--a--a--a--a--a--a--a--a feature
>                        /
> --x--x--x--x--x--x--x--x--x--x--x--x master
>   \
>    o--o--o--o--o--o--o 12.72.1
>
>
> Work flow :
>
> $ git checkout 12.72.1
> $ git rebase --onto 12.72.1 master feature
>
> a lot of conflicts, resolving and git rebase --continue
>
> And then, at the end of the rebase, without me doing anything, feature
> branch is checked out and it seems that its HEAD has been reset to the
> new 12.72.1 HEAD.
>
> --x--x--x--x--x--x--x--x--x--x--x--x master
>   \
>    o--o--o--o--o--o--o--a--a--a--a--a--a--a--a--a 12.72.1 feature
>
> Is that normal ? If it is, how do I do to avoid my feature branch to  
> be
> reset at 12.72.1's HEAD ?
>
> Any enlightenment is very welcome.

Look at the "git-rebase" man page, particularly the order of the  
arguments, what they mean, and the usage examples of "--onto":

   $ git rebase --onto 12.72.1 master feature

Means, "replay these changes on top of 12.72.1", where "these changes"  
refers to commits on branch "feature" with upstream "master", which is  
what "git rebase" did for you.

If you actually want the "feature" branch to continue pointing at the  
old feature branch rather than your newly rebased one, you could just  
look up the old SHA1 for it and update it with:

   $ git branch -f feature abcd1234

Where "abcd1234" is the hash of the old "feature" HEAD.

But I don't really know why you'd want to do that. The purpose of "git  
rebase" isn't to copy or cherry-pick commits from one branch onto  
another, but to actually _move_ (or transplant, or replay, if you  
prefer) those commits.

Maybe I misunderstood your intentions though.

Cheers,
Wincent

```

## Tay Ray Chuan, 2009-12-31 05:01

Subject: Re: Need some help with git rebase
Message-ID: <be6fef0d0912302101ta010dfamab05b751a0ceee76@mail.gmail.com>
URL: https://gitlist.dev/e/be6fef0d0912302101ta010dfamab05b751a0ceee76%40mail.gmail.com
In-Reply-To: <1262211866.7068.1.camel@kheops>

```
Hi,

On Thu, Dec 31, 2009 at 6:24 AM, Sylvain Rabot <sylvain@abstraction.fr> wrote:
> And then, at the end of the rebase, without me doing anything, feature
> branch is checked out and it seems that its HEAD has been reset to the
> new 12.72.1 HEAD.
>
> --x--x--x--x--x--x--x--x--x--x--x--x master
>   \
>    o--o--o--o--o--o--o--a--a--a--a--a--a--a--a--a 12.72.1 feature
>
> Is that normal ? If it is, how do I do to avoid my feature branch to be
> reset at 12.72.1's HEAD ?

reading the manual, I think this is normal.

According to the third paragraph of the description of git-rebase, the
branch feature will be reset to 12.72.1.

You can just rename the branch back to 12.72.1, and retrieve the old
tip of feature by examining the reflog.

-- 
Cheers,
Ray Chuan

```

## Sylvain Rabot, 2009-12-31 09:02

Subject: Re: Need some help with git rebase
Message-ID: <7fce93be0912310102x53755120o31e42c4a7a92a709@mail.gmail.com>
URL: https://gitlist.dev/e/7fce93be0912310102x53755120o31e42c4a7a92a709%40mail.gmail.com
In-Reply-To: <CB5B49CA-0C66-4384-9B47-3675E517E203@wincent.com>

```
On Wed, Dec 30, 2009 at 23:46, Wincent Colaiuta <win@wincent.com> wrote:
>
> Look at the "git-rebase" man page, particularly the order of the arguments, what they mean, and the usage examples of "--onto":
>
>  $ git rebase --onto 12.72.1 master feature
>
> Means, "replay these changes on top of 12.72.1", where "these changes" refers to commits on branch "feature" with upstream "master", which is what "git rebase" did for you.
>
> If you actually want the "feature" branch to continue pointing at the old feature branch rather than your newly rebased one, you could just look up the old SHA1 for it and update it with:
>
>  $ git branch -f feature abcd1234
>
> Where "abcd1234" is the hash of the old "feature" HEAD.
>
> But I don't really know why you'd want to do that. The purpose of "git rebase" isn't to copy or cherry-pick commits from one branch onto another, but to actually _move_ (or transplant, or replay, if you prefer) those commits.
>
> Maybe I misunderstood your intentions though.
>
> Cheers,
> Wincent
>

In fact I want to backport the commits of the feature branch into 12.72.1.
I used git rebase because the drawings of the man page looked like
that I wanted to do and it does except for the part it resets the head
of my feature branch.

But the good behavior would be to cherry pick each commit of the
feature branch and apply them into 12.72.1, right ?

Thanks for your answer.

Regards.

--
Sylvain

```

## Peter Baumann, 2009-12-31 09:32

Subject: Re: Need some help with git rebase
Message-ID: <20091231093200.GB24460@m62s10.vlinux.de>
URL: https://gitlist.dev/e/20091231093200.GB24460%40m62s10.vlinux.de
In-Reply-To: <7fce93be0912310102x53755120o31e42c4a7a92a709@mail.gmail.com>

```
On Thu, Dec 31, 2009 at 10:02:12AM +0100, Sylvain Rabot wrote:
> On Wed, Dec 30, 2009 at 23:46, Wincent Colaiuta <win@wincent.com> wrote:
> >
> > Look at the "git-rebase" man page, particularly the order of the arguments, what they mean, and the usage examples of "--onto":
> >
> >  $ git rebase --onto 12.72.1 master feature
> >
> > Means, "replay these changes on top of 12.72.1", where "these changes" refers to commits on branch "feature" with upstream "master", which is what "git rebase" did for you.
> >
> > If you actually want the "feature" branch to continue pointing at the old feature branch rather than your newly rebased one, you could just look up the old SHA1 for it and update it with:
> >
> >  $ git branch -f feature abcd1234
> >
> > Where "abcd1234" is the hash of the old "feature" HEAD.
> >
> > But I don't really know why you'd want to do that. The purpose of "git rebase" isn't to copy or cherry-pick commits from one branch onto another, but to actually _move_ (or transplant, or replay, if you prefer) those commits.
> >
> > Maybe I misunderstood your intentions though.
> >
> > Cheers,
> > Wincent
> >
> 
> In fact I want to backport the commits of the feature branch into 12.72.1.
> I used git rebase because the drawings of the man page looked like
> that I wanted to do and it does except for the part it resets the head
> of my feature branch.
> 
> But the good behavior would be to cherry pick each commit of the
> feature branch and apply them into 12.72.1, right ?
> 

$ git checkout -b rebased_feature feature
$ git rebase --onto 12.72.1 master rebased_feature

will create a temporary branch named "rebased_feature" pointing to the same
commit as the branch "feature". In fact, this will rebase the commits on the
feature branch not reachable from master onto your 12.72.1 branch *and* won't
reset the feature branch. Instead the temporary branch named "rebased_feature"
will be rebased ontop of 12.72.1.

I would still prefere the rebase over doing multiple cherry picks.

-Peter

```

## Wincent Colaiuta, 2009-12-31 11:06

Subject: Re: Need some help with git rebase
Message-ID: <89AAB33C-89D4-46E9-A950-1CBFB4D2CBB3@wincent.com>
URL: https://gitlist.dev/e/89AAB33C-89D4-46E9-A950-1CBFB4D2CBB3%40wincent.com
In-Reply-To: <7fce93be0912301502r77152c52sbccf762fb6c44610@mail.gmail.com>

```
El 31/12/2009, a las 00:02, Sylvain Rabot escribió:

> In fact I want to backport the commits of the feature branch into  
> 12.72.1.
>
> I used git rebase because the drawings of the man page looked like  
> that I
> wanted to do and it does except for the part it resets the head of my
> feature branch.
>
> But as you said the good behavior would be to cherry pick each  
> commit of the
> feature branch and apply them into 12.72.1, right ?

Well rebasing is just a convenient way of cherry-picking a bunch of  
commits, so it's probably the right tool for the job.

But as you've seen, it has the effect of "moving" or "transplanting"  
the feature branch (replacing the old feature HEAD). If you really  
want the original feature branch HEAD to continue existing after the  
rebase you'll need to take some specific action to preserve it  
beforehand (creating a temporary branch before doing the rebase like  
Peter Baumann suggested) or restore it afterwards (using "git branch"  
like I suggested).

But before you actually do that, I'd make sure that you actually have  
a valid reason for keeping that branch around. Maybe wanting to  
"backport" those commits onto various different branches might be a  
valid reason. But it's worth thinking through because Git gives you  
various tools for supporting different workflows (merging, rebasing,  
cherry-picking) and they each have their use cases.

Cheers,
Wincent

```
