# Flatten history

5 messages from 2013-07-30 to 2013-07-30. Participants: Hilco Wijbenga, Felipe Contreras, Bryan Turner.
Thread: https://gitlist.dev/t/34565

## Hilco Wijbenga, 2013-07-30 01:42

Subject: Flatten history
Message-ID: <CAE1pOi0CQ1k3h3ie=s3qvkQog9foYBOnJ++uuum-Br7vzQHRSQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAE1pOi0CQ1k3h3ie%3Ds3qvkQog9foYBOnJ%2B%2Buuum-Br7vzQHRSQ%40mail.gmail.com

```
Hi all,

I have a (public) "feature" branch that has been kept up-to-date with
"master" by regularly merging master back into it. I would now like to
get all the changes from feature but not any of the commits.
Basically, I want to replay all of feature's commits without creating
those commits.

I thought something like

git cherry-pick -n abcd^..feature

should do the trick (while on master, where abcd is the SHA-1 of the
commit where feature was created) but I get conflicts.

First, why the conflicts? I have done all the merges so cherry-pick
should simply be able to replay them? Second, what is the correct way
of doing this?

Cheers,
Hilco

P.S. The most annoying thing is that I've done this exact thing before
but I can't find what command I used. :-)

```

## Felipe Contreras, 2013-07-30 03:50

Subject: Re: Flatten history
Message-ID: <CAMP44s2pXSN2HbpGLW9jrgJAypbLM3JtgD+nyK7LkNdvH4nsfQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s2pXSN2HbpGLW9jrgJAypbLM3JtgD%2BnyK7LkNdvH4nsfQ%40mail.gmail.com
In-Reply-To: <CAE1pOi0CQ1k3h3ie=s3qvkQog9foYBOnJ++uuum-Br7vzQHRSQ@mail.gmail.com>

```
On Mon, Jul 29, 2013 at 8:42 PM, Hilco Wijbenga
<hilco.wijbenga@gmail.com> wrote:
> Hi all,
>
> I have a (public) "feature" branch that has been kept up-to-date with
> "master" by regularly merging master back into it. I would now like to
> get all the changes from feature but not any of the commits.
> Basically, I want to replay all of feature's commits without creating
> those commits.
>
> I thought something like
>
> git cherry-pick -n abcd^..feature
>
> should do the trick (while on master, where abcd is the SHA-1 of the
> commit where feature was created) but I get conflicts.
>
> First, why the conflicts? I have done all the merges so cherry-pick
> should simply be able to replay them? Second, what is the correct way
> of doing this?

Perhaps

% git cherry-pick -n --no-merges --right-only --topo-order
--cherry-pick abcd^..feature

-- 
Felipe Contreras

```

## Bryan Turner, 2013-07-30 03:59

Subject: Re: Flatten history
Message-ID: <CAGyf7-FXp-a+HmoRQBrUWu2xc-UvbsZUfZz7GTce2JzwrsfMVw@mail.gmail.com>
URL: https://gitlist.dev/e/CAGyf7-FXp-a%2BHmoRQBrUWu2xc-UvbsZUfZz7GTce2JzwrsfMVw%40mail.gmail.com
In-Reply-To: <CAMP44s2pXSN2HbpGLW9jrgJAypbLM3JtgD+nyK7LkNdvH4nsfQ@mail.gmail.com>

```
On 30 July 2013 13:50, Felipe Contreras <felipe.contreras@gmail.com> wrote:
> On Mon, Jul 29, 2013 at 8:42 PM, Hilco Wijbenga
> <hilco.wijbenga@gmail.com> wrote:
>> Hi all,
>>
>> I have a (public) "feature" branch that has been kept up-to-date with
>> "master" by regularly merging master back into it. I would now like to
>> get all the changes from feature but not any of the commits.
>> Basically, I want to replay all of feature's commits without creating
>> those commits.
>>
>> I thought something like
>>
>> git cherry-pick -n abcd^..feature
>>
>> should do the trick (while on master, where abcd is the SHA-1 of the
>> commit where feature was created) but I get conflicts.
>>
>> First, why the conflicts? I have done all the merges so cherry-pick
>> should simply be able to replay them? Second, what is the correct way
>> of doing this?
>
> Perhaps
>
> % git cherry-pick -n --no-merges --right-only --topo-order
> --cherry-pick abcd^..feature
>
> --
> Felipe Contreras

Wouldn't git merge --squash do what you're looking for? It seems like
the only way to not get conflicts trying to cherry pick is if you
never had any conflicts while you were merging master into your
feature branch. "Evil" merges, where you actually have to change code,
even if it's just to resolve conflicts, don't tend to replay
correctly.

It seems like this should do it:
% git checkout master
Switched to branch 'master'
% git merge --squash feature
Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested
% git commit

git merge --squash will just apply the changes without creating a
commit. You can then make any final changes you want to and write your
commit message for the feature.

Hope this helps,
Bryan Turner

```

## Hilco Wijbenga, 2013-07-30 04:05

Subject: Re: Flatten history
Message-ID: <CAE1pOi0LKy8hsjAEsFPPN+9mJRDoEE0a3sMv7gpnW8V95_W9sA@mail.gmail.com>
URL: https://gitlist.dev/e/CAE1pOi0LKy8hsjAEsFPPN%2B9mJRDoEE0a3sMv7gpnW8V95_W9sA%40mail.gmail.com
In-Reply-To: <CAMP44s2pXSN2HbpGLW9jrgJAypbLM3JtgD+nyK7LkNdvH4nsfQ@mail.gmail.com>

```
On 29 July 2013 20:50, Felipe Contreras <felipe.contreras@gmail.com> wrote:
> On Mon, Jul 29, 2013 at 8:42 PM, Hilco Wijbenga
> <hilco.wijbenga@gmail.com> wrote:
>> Hi all,
>>
>> I have a (public) "feature" branch that has been kept up-to-date with
>> "master" by regularly merging master back into it. I would now like to
>> get all the changes from feature but not any of the commits.
>> Basically, I want to replay all of feature's commits without creating
>> those commits.
>>
>> I thought something like
>>
>> git cherry-pick -n abcd^..feature
>>
>> should do the trick (while on master, where abcd is the SHA-1 of the
>> commit where feature was created) but I get conflicts.
>>
>> First, why the conflicts? I have done all the merges so cherry-pick
>> should simply be able to replay them? Second, what is the correct way
>> of doing this?
>
> Perhaps
>
> % git cherry-pick -n --no-merges --right-only --topo-order
> --cherry-pick abcd^..feature

Thank you for the suggestion but this still gives me conflicts.

```

## Hilco Wijbenga, 2013-07-30 04:08

Subject: Re: Flatten history
Message-ID: <CAE1pOi0qQvPrG8te0kKVpPDx4LqSEuBHVw+-NRaxH1HT9CvqxA@mail.gmail.com>
URL: https://gitlist.dev/e/CAE1pOi0qQvPrG8te0kKVpPDx4LqSEuBHVw%2B-NRaxH1HT9CvqxA%40mail.gmail.com
In-Reply-To: <CAGyf7-FXp-a+HmoRQBrUWu2xc-UvbsZUfZz7GTce2JzwrsfMVw@mail.gmail.com>

```
On 29 July 2013 20:59, Bryan Turner <bturner@atlassian.com> wrote:
> On 30 July 2013 13:50, Felipe Contreras <felipe.contreras@gmail.com> wrote:
>> On Mon, Jul 29, 2013 at 8:42 PM, Hilco Wijbenga
>> <hilco.wijbenga@gmail.com> wrote:
>>> Hi all,
>>>
>>> I have a (public) "feature" branch that has been kept up-to-date with
>>> "master" by regularly merging master back into it. I would now like to
>>> get all the changes from feature but not any of the commits.
>>> Basically, I want to replay all of feature's commits without creating
>>> those commits.
>>>
>>> I thought something like
>>>
>>> git cherry-pick -n abcd^..feature
>>>
>>> should do the trick (while on master, where abcd is the SHA-1 of the
>>> commit where feature was created) but I get conflicts.
>>>
>>> First, why the conflicts? I have done all the merges so cherry-pick
>>> should simply be able to replay them? Second, what is the correct way
>>> of doing this?
>>
>> Perhaps
>>
>> % git cherry-pick -n --no-merges --right-only --topo-order
>> --cherry-pick abcd^..feature
>>
>> --
>> Felipe Contreras
>
> Wouldn't git merge --squash do what you're looking for? It seems like
> the only way to not get conflicts trying to cherry pick is if you
> never had any conflicts while you were merging master into your
> feature branch. "Evil" merges, where you actually have to change code,
> even if it's just to resolve conflicts, don't tend to replay
> correctly.
>
> It seems like this should do it:
> % git checkout master
> Switched to branch 'master'
> % git merge --squash feature
> Squash commit -- not updating HEAD
> Automatic merge went well; stopped before committing as requested
> % git commit
>
> git merge --squash will just apply the changes without creating a
> commit. You can then make any final changes you want to and write your
> commit message for the feature.

Ah, yes "git merge --squash feature" seems to do exactly what I was
looking for. Funny, I thought I did something with rev-list last time
but this --squash is much simpler. :-) Thank you!

```
