# Re: [Q] merge squash unexpected conflicts

11 messages from 2009-05-14 to 2009-05-14. Participants: Cory Sharp, Junio C Hamano, Michael Radziej, Michael J Gruber.
Thread: https://gitlist.dev/t/19342

## Cory Sharp, 2009-05-14 02:42

Subject: Re: [Q] merge squash unexpected conflicts
Message-ID: <bb9d69200905131942t7a43a29fh9638d2548e9f12dc@mail.gmail.com>
URL: https://gitlist.dev/e/bb9d69200905131942t7a43a29fh9638d2548e9f12dc%40mail.gmail.com
In-Reply-To: <bb9d69200905131706m61b0dda1xc347ca2e719ec142@mail.gmail.com>

```
Using git 1.6.3.1, when using "git merge --squash" I get unexpected
conflicts when merging an update to a file that was added after the
original branch point, like this

  * Initialize git repo
  * Add hello to master
  * Create topic branch
  * Add goodbye to master
  * Merge squash master into topic, gets new goodbye
  * Update goodbye in master
  * Again merge squash master into topic, update goodbye

The second merge squash produces a conflict in goodbye.

Am I doing something a little wrong or unexpected?  Is there a way
around this squash conflict behavior?  This doesn't seem to happen
with plain merge without squash.  I've appended a small bash script to
show this behavior - run it from an empty directory.

Thanks,
Cory


#!/bin/sh

try() {
    echo "$@"
    "$@" || exit 1
}

note() {
    echo
    echo "##" "$@" "##"
}

[ -d .git ] && echo .git already exists, aborting. && exit 1

note "Initialize git repo"
try git init

note "Add hello to master"
echo "hello world" > hello.txt
try git add hello.txt
try git commit -m "Added hello"

note "Create topic branch"
try git checkout -b topic

note "Add goodbye to master"
try git checkout master
echo "farewell world" > goodbye.txt
try git add goodbye.txt
try git commit -m "Added goodbye"

note "Merge master into topic, gets new goodbye"
try git checkout topic
try git merge --squash master
try git commit -m "Merged master"

note "Update goodbye in master"
try git checkout master
echo "goodbye world" > goodbye.txt
try git add goodbye.txt
try git commit -m "Updated goodbye"

note "Again merge master into topic, update goodbye"
try git checkout topic
try git merge --squash master

```

## Junio C Hamano, 2009-05-14 03:21

Subject: Re: [Q] merge squash unexpected conflicts
Message-ID: <7v4ovo1iap.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v4ovo1iap.fsf%40alter.siamese.dyndns.org
In-Reply-To: <bb9d69200905131942t7a43a29fh9638d2548e9f12dc@mail.gmail.com>

```
Cory Sharp <cory.sharp@gmail.com> writes:

> Am I doing something a little wrong or unexpected?  Is there a way
> around this squash conflict behavior?  This doesn't seem to happen
> with plain merge without squash.

Of course.  That's the whole point of recording a merge as a merge.

```

## Cory Sharp, 2009-05-14 03:57

Subject: Re: [Q] merge squash unexpected conflicts
Message-ID: <bb9d69200905132057u60adc2f8vb9ba9a35791f72ac@mail.gmail.com>
URL: https://gitlist.dev/e/bb9d69200905132057u60adc2f8vb9ba9a35791f72ac%40mail.gmail.com
In-Reply-To: <7v4ovo1iap.fsf@alter.siamese.dyndns.org>

```
On Wed, May 13, 2009 at 8:21 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Cory Sharp <cory.sharp@gmail.com> writes:
>
>> Am I doing something a little wrong or unexpected?  Is there a way
>> around this squash conflict behavior?  This doesn't seem to happen
>> with plain merge without squash.
>
> Of course.  That's the whole point of recording a merge as a merge.
>

$ git help merge

  --squash
           Produce the working tree and index state as if a real merge
happened. ... This allows you to create a
           single commit on top of the current branch whose effect is
the same as merging another branch.

```

## Junio C Hamano, 2009-05-14 04:42

Subject: Re: [Q] merge squash unexpected conflicts
Message-ID: <7veiusz45w.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7veiusz45w.fsf%40alter.siamese.dyndns.org
In-Reply-To: <bb9d69200905132057u60adc2f8vb9ba9a35791f72ac@mail.gmail.com>

```
Cory Sharp <cory.sharp@gmail.com> writes:

> On Wed, May 13, 2009 at 8:21 PM, Junio C Hamano <gitster@pobox.com> wrote:
> ..
>> Of course.  That's the whole point of recording a merge as a merge.
>>
>
> $ git help merge
>
>   --squash
>            Produce the working tree and index state as if a real merge
> happened. ... This allows you to create a
>            single commit on top of the current branch whose effect is
> the same as merging another branch.

What's your point?

WIth --squash, the tree and the index state becomes the same as if a real
merge happened.  But the merge history is discarded with --squash.  It is
a simulation of a merge in CVS and SVN (before they added "merge tracking").

If you want support for repeated merges by merge tracking, you do not want
todiscard the merge history by using --squash.

```

## Cory Sharp, 2009-05-14 06:34

Subject: Re: [Q] merge squash unexpected conflicts
Message-ID: <bb9d69200905132334m7a4e3a4akde3529abeab5a09@mail.gmail.com>
URL: https://gitlist.dev/e/bb9d69200905132334m7a4e3a4akde3529abeab5a09%40mail.gmail.com
In-Reply-To: <7veiusz45w.fsf@alter.siamese.dyndns.org>

```
On Wed, May 13, 2009 at 9:42 PM, Junio C Hamano <gitster@pobox.com> wrote:
> What's your point?

I am asking for help and understanding.

> WIth --squash, the tree and the index state becomes the same as if a real
> merge happened.  But the merge history is discarded with --squash.  It is
> a simulation of a merge in CVS and SVN (before they added "merge tracking").
>
> If you want support for repeated merges by merge tracking, you do not want
> todiscard the merge history by using --squash.

Why doesn't --squash do merge tracking?  The help didn't indicate that
it doesn't, and I don't understand why it shouldn't -- since I *could*
track the previous merge point manually and do "git diff --binary
PREV_MERGE..NEXT_MERGE | git apply -" to do the merge myself.

But since that's me manually performing merge tracking, why doesn't
"merge --squash" track like just "merge" does?  If I didn't want
tracking, I would expect to use some other command than "git merge
[options]".

Thanks for your help,
Cory

```

## Junio C Hamano, 2009-05-14 06:42

Subject: Re: [Q] merge squash unexpected conflicts
Message-ID: <7v4ovoxk0n.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v4ovoxk0n.fsf%40alter.siamese.dyndns.org
In-Reply-To: <bb9d69200905132334m7a4e3a4akde3529abeab5a09@mail.gmail.com>

```
Cory Sharp <cory.sharp@gmail.com> writes:

>> If you want support for repeated merges by merge tracking, you do not want
>> todiscard the merge history by using --squash.
>
> Why doesn't --squash do merge tracking?  The help didn't indicate that
> it doesn't, and I don't understand why ...

Because "merge" is (no surprise) what tracks what (two or more) things
were merged.  And with --squash you are choosing not to make a merge.  I
am not sure if there is any more thing to be explained...

```

## Cory Sharp, 2009-05-14 06:54

Subject: Re: [Q] merge squash unexpected conflicts
Message-ID: <bb9d69200905132354h6b64171g24351840fb1d0893@mail.gmail.com>
URL: https://gitlist.dev/e/bb9d69200905132354h6b64171g24351840fb1d0893%40mail.gmail.com
In-Reply-To: <7v4ovoxk0n.fsf@alter.siamese.dyndns.org>

```
On Wed, May 13, 2009 at 11:42 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Because "merge" is (no surprise) what tracks what (two or more) things
> were merged.  And with --squash you are choosing not to make a merge.  I
> am not sure if there is any more thing to be explained...

Yeah I'm not quite getting it.  Thanks for trying to explain, though.

```

## Michael Radziej, 2009-05-14 07:01

Subject: Re: [Q] merge squash unexpected conflicts
Message-ID: <20090514070129.GL8212@noris.de>
URL: https://gitlist.dev/e/20090514070129.GL8212%40noris.de
In-Reply-To: <bb9d69200905132354h6b64171g24351840fb1d0893@mail.gmail.com>

```
On Wed, May 13, Cory Sharp wrote:

> Yeah I'm not quite getting it.  Thanks for trying to explain, though.

git merge --squash is not a merge at all. It only creates a regular commit
with one parent. It is useful only in very special circumstances.


Michael

-- 
noris network AG - Deutschherrnstraße 15-19 - D-90429 Nürnberg -
Tel +49-911-9352-0 - Fax +49-911-9352-100
http://www.noris.de - The IT-Outsourcing Company
 
Vorstand: Ingo Kraupa (Vorsitzender), Joachim Astel, Hansjochen Klenk - 
Vorsitzender des Aufsichtsrats: Stefan Schnabel - AG Nürnberg HRB 17689

```

## Michael J Gruber, 2009-05-14 12:17

Subject: Re: [Q] merge squash unexpected conflicts
Message-ID: <4A0C0BDF.9020803@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4A0C0BDF.9020803%40drmicha.warpmail.net
In-Reply-To: <bb9d69200905132057u60adc2f8vb9ba9a35791f72ac@mail.gmail.com>

```
Cory Sharp venit, vidit, dixit 14.05.2009 05:57:
> On Wed, May 13, 2009 at 8:21 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Cory Sharp <cory.sharp@gmail.com> writes:
>>
>>> Am I doing something a little wrong or unexpected?  Is there a way
>>> around this squash conflict behavior?  This doesn't seem to happen
>>> with plain merge without squash.
>>
>> Of course.  That's the whole point of recording a merge as a merge.
>>
> 
> $ git help merge
> 
>   --squash
>            Produce the working tree and index state as if a real merge
> happened. ... This allows you to create a
>            single commit on top of the current branch whose effect is
> the same as merging another branch.

The problem is simply in the "...". You cut out the vital part:


        but do not actually make a commit or
        move the `HEAD`, nor record `$GIT_DIR/MERGE_HEAD` to
        cause the next `git commit` command to create a merge
        commit.

See? Tree: yes, index: yes, merge info: no.

Git does perform a (tree) merge with --squash, but records the resulting
tree as an ordinary non-merge commit (with a single parent).

I'm not sure whether the statement about the index is completely
correct, though. During a merge the index records info about the merge
(stages :1: etc.) but that as missing with --squash. Only the resulting
tree is added to the index. How about the below?

Michael

diff --git a/Documentation/merge-options.txt
b/Documentation/merge-options.txt
index 637b53f..adadf8e 100644
--- a/Documentation/merge-options.txt
+++ b/Documentation/merge-options.txt
@@ -39,7 +39,8 @@

 --squash::
        Produce the working tree and index state as if a real
-       merge happened, but do not actually make a commit or
+       merge happened (except for the merge information),
+       but do not actually make a commit or
        move the `HEAD`, nor record `$GIT_DIR/MERGE_HEAD` to
        cause the next `git commit` command to create a merge
        commit.  This allows you to create a single commit on

```

## Cory Sharp, 2009-05-14 14:47

Subject: Re: [Q] merge squash unexpected conflicts
Message-ID: <bb9d69200905140747j60b2e09flaabbb4db09b371b4@mail.gmail.com>
URL: https://gitlist.dev/e/bb9d69200905140747j60b2e09flaabbb4db09b371b4%40mail.gmail.com
In-Reply-To: <4A0C0BDF.9020803@drmicha.warpmail.net>

```
On Thu, May 14, 2009 at 5:17 AM, Michael J Gruber
<git@drmicha.warpmail.net> wrote:
> Cory Sharp venit, vidit, dixit 14.05.2009 05:57:
>> On Wed, May 13, 2009 at 8:21 PM, Junio C Hamano <gitster@pobox.com> wrote:
>>> Cory Sharp <cory.sharp@gmail.com> writes:
>>>
>>>> Am I doing something a little wrong or unexpected?  Is there a way
>>>> around this squash conflict behavior?  This doesn't seem to happen
>>>> with plain merge without squash.
>>>
>>> Of course.  That's the whole point of recording a merge as a merge.
>>>
>>
>> $ git help merge
>>
>>   --squash
>>            Produce the working tree and index state as if a real merge
>> happened. ... This allows you to create a
>>            single commit on top of the current branch whose effect is
>> the same as merging another branch.
>
> The problem is simply in the "...". You cut out the vital part:
>
>
>        but do not actually make a commit or
>        move the `HEAD`, nor record `$GIT_DIR/MERGE_HEAD` to
>        cause the next `git commit` command to create a merge
>        commit.
>
> See? Tree: yes, index: yes, merge info: no.
>
> Git does perform a (tree) merge with --squash, but records the resulting
> tree as an ordinary non-merge commit (with a single parent).
>
> I'm not sure whether the statement about the index is completely
> correct, though. During a merge the index records info about the merge
> (stages :1: etc.) but that as missing with --squash. Only the resulting
> tree is added to the index. How about the below?

Now I see, thanks for the help.  The elided part, at the time I elided
it, did not make me understand that merge info was not written,
particularly when surrounded by its original accompanying text.

Thanks again,
Cory

```

## Cory Sharp, 2009-05-14 18:25

Subject: Re: [Q] merge squash unexpected conflicts
Message-ID: <bb9d69200905141125i4a8ffaa8j6aea2a6c44de0c7d@mail.gmail.com>
URL: https://gitlist.dev/e/bb9d69200905141125i4a8ffaa8j6aea2a6c44de0c7d%40mail.gmail.com
In-Reply-To: <20090514070129.GL8212@noris.de>

```
On Thu, May 14, 2009 at 12:01 AM, Michael Radziej <mir@noris.de> wrote:
> git merge --squash is not a merge at all. ...
> It is useful only in very special circumstances.

You're right.  I (incorrectly) thought I had to use --squash to
properly interface with an svn branch and trunk through git-svn.  I
thought not using squash would trigger hundreds of commits - it
doesn't, nice things happen with just "merge".

Thanks everyone for helping me,
Cory

```
