# put THEIR commits AFTER my commits with a single rebase command

6 messages from 2013-04-18 to 2013-04-18. Participants: Ilya Basin, Johannes Sixt, Johan Herland.
Thread: https://gitlist.dev/t/33531

## Ilya Basin, 2013-04-18 05:18

Subject: put THEIR commits AFTER my commits with a single rebase command
Message-ID: <1928280357.20130418091807@gmail.com>
URL: https://gitlist.dev/e/1928280357.20130418091807%40gmail.com

```
I asked this on stackoverflow, but no reply.
http://stackoverflow.com/questions/15971244/git-put-their-commits-after-my-commits-with-a-single-rebase-command

Suppose master and origin/master diverged.
I'm on master and I want to put the commits from origin/master after my commits and then push --force.  

         A---B---C origin/master
        /
    D---E---F---G *master

desired result:

         A---B---C origin/master
        /
    D---E---F---G---A'---B'---C' *master



Variant 1:

    git branch -f tmp
    git reset --hard origin/master
    git rebase tmp

This variant is bad, because 'git reset --hard' checks out some files and 'git rebase' rewrites them again before applying commits. It's a redundant job.  
Variant 2:

    git branch -f tmp origin/master
    git rebase --onto master master tmp
    git branch -f master
    git checkout master

Too many commands. I want to do this with just one command. And I want
to stay be on branch master in case of rebase conflicts.

```

## Johan Herland, 2013-04-18 06:21

Subject: Re: put THEIR commits AFTER my commits with a single rebase command
Message-ID: <CALKQrgeYrsOOR9z+khOkGWhy38LPXwHFo9wf8RrZr3LsM3zTAg@mail.gmail.com>
URL: https://gitlist.dev/e/CALKQrgeYrsOOR9z%2BkhOkGWhy38LPXwHFo9wf8RrZr3LsM3zTAg%40mail.gmail.com
In-Reply-To: <1928280357.20130418091807@gmail.com>

```
On Thu, Apr 18, 2013 at 7:18 AM, Ilya Basin <basinilya@gmail.com> wrote:
> I asked this on stackoverflow, but no reply.
> http://stackoverflow.com/questions/15971244/git-put-their-commits-after-my-commits-with-a-single-rebase-command
>
> Suppose master and origin/master diverged.
> I'm on master and I want to put the commits from origin/master after my commits and then push --force.
>
>          A---B---C origin/master
>         /
>     D---E---F---G *master
>
> desired result:
>
>          A---B---C origin/master
>         /
>     D---E---F---G---A'---B'---C' *master

Note that if other people are working on top of origin/master, then
what you are proposing is quite rude to them, since they must now
manually rebase their own work on top of your rebased history.
Rewriting public history is generally considered evil.

> Variant 1:
>
>     git branch -f tmp
>     git reset --hard origin/master
>     git rebase tmp
>
> This variant is bad, because 'git reset --hard' checks out some files and 'git rebase' rewrites them again before applying commits. It's a redundant job.
> Variant 2:
>
>     git branch -f tmp origin/master
>     git rebase --onto master master tmp
>     git branch -f master
>     git checkout master
>
> Too many commands. I want to do this with just one command. And I want
> to stay be on branch master in case of rebase conflicts.

git cherry-pick master..origin/master


...Johan

--
Johan Herland, <johan@herland.net>
www.herland.net

```

## Johannes Sixt, 2013-04-18 06:31

Subject: Re: put THEIR commits AFTER my commits with a single rebase command
Message-ID: <516F9329.4060405@viscovery.net>
URL: https://gitlist.dev/e/516F9329.4060405%40viscovery.net
In-Reply-To: <1928280357.20130418091807@gmail.com>

```
Am 4/18/2013 7:18, schrieb Ilya Basin:
> desired result:
> 
>          A---B---C origin/master
>         /
>     D---E---F---G---A'---B'---C' *master
> 
> 
> 
> Variant 1:
> 
>     git branch -f tmp
>     git reset --hard origin/master
>     git rebase tmp

Variant 1a:

   git reset --hard origin/master
   git rebase @{1}

> 
> This variant is bad, because 'git reset --hard' checks out some files
> and 'git rebase' rewrites them again before applying commits. It's a
redundant job.
>
> Variant 2:
> 
>     git branch -f tmp origin/master
>     git rebase --onto master master tmp
>     git branch -f master
>     git checkout master
> 
> Too many commands. I want to do this with just one command. And I want
> to stay be on branch master in case of rebase conflicts.

Perhaps this one:

   git merge origin/master
   git rebase ORIG_HEAD

-- Hannes

```

## Ilya Basin, 2013-04-18 06:59

Subject: Re[2]: put THEIR commits AFTER my commits with a single rebase command
Message-ID: <1279652941.20130418105900@gmail.com>
URL: https://gitlist.dev/e/1279652941.20130418105900%40gmail.com
In-Reply-To: <CALKQrgeYrsOOR9z+khOkGWhy38LPXwHFo9wf8RrZr3LsM3zTAg@mail.gmail.com>

```
JH> git cherry-pick master..origin/master

Thanks Johan.

```

## Ilya Basin, 2013-04-18 08:33

Subject: Re[2]: put THEIR commits AFTER my commits with a single rebase command
Message-ID: <1949082828.20130418123321@gmail.com>
URL: https://gitlist.dev/e/1949082828.20130418123321%40gmail.com
In-Reply-To: <516F9329.4060405@viscovery.net>

```

JS> Perhaps this one:

JS>    git merge origin/master
JS>    git rebase ORIG_HEAD

JS> -- Hannes

Wouldn't I have to resolve conflicts twice?


BTW, during the rebase, can I tell git to rewrite a different branch
upon rebase success or abort?

    git branch -f tmp origin/master
    git rebase --onto master master tmp
    if [ $? -ne 0 ]; then
       # modify some file in .git/ ?
    else
        git branch -f master
        git checkout master
    fi



-- 

```

## Johannes Sixt, 2013-04-18 11:03

Subject: Re: put THEIR commits AFTER my commits with a single rebase command
Message-ID: <516FD2EE.4040300@viscovery.net>
URL: https://gitlist.dev/e/516FD2EE.4040300%40viscovery.net
In-Reply-To: <1949082828.20130418123321@gmail.com>

```
Am 4/18/2013 10:33, schrieb Ilya Basin:
> 
> JS> Perhaps this one:
> 
> JS>    git merge origin/master
> JS>    git rebase ORIG_HEAD
> 
> JS> -- Hannes
> 
> Wouldn't I have to resolve conflicts twice?

Yes. But you did run 'git config rerere.enabled true' when you started
with git, didn't you? ;-)

Anyway, Johan's idea to use git cherry-pick is much better.

> BTW, during the rebase, can I tell git to rewrite a different branch
> upon rebase success or abort?
> 
>     git branch -f tmp origin/master
>     git rebase --onto master master tmp
>     if [ $? -ne 0 ]; then
>        # modify some file in .git/ ?

What do you expect here? Failure of git rebase means that it is not
complete, yet. So far, nothing has been rewritten. So what? Perhaps you mean:
	# never mind
	git rebase --abort

>     else
>         git branch -f master
>         git checkout master
>     fi

-- Hannes

```
