From: Junio C Hamano <gitster@pobox.com>
To: mu gsh <yue937@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: git merge bug report
Date: Tue, 15 Apr 2025 06:52:08 -0700 [thread overview]
Message-ID: <xmqqtt6po7lj.fsf@gitster.g> (raw)
In-Reply-To: <CAE8aReXOwM8ByyObxrb8NhRMYfK1OB_6B9eOO07mYXMkp_E8EA@mail.gmail.com> (mu gsh's message of "Tue, 15 Apr 2025 20:23:30 +0800")
mu gsh <yue937@gmail.com> writes:
> cat > models.py <<EOF
> class User:
> name = "str"
>
>
> class Product:
> id = 0
> EOF
> git add models.py
> git commit -m "initial: User and Product class"
>
> # feature1
> git checkout -b feature
> cat > models.py <<EOF
> class User:
> name = "str"
>
> def user_method(self):
> return
>
>
> class Product:
> id = 0
> EOF
> git commit -am "feature: add method to User"
>
> # feature 2
> git checkout master
> cat > models.py <<EOF
> class User:
> name = "str"
> bugger = "fix me"
>
>
> class NoMethod:
> pass
>
>
> class Product:
> id = 0
> EOF
> git commit -am "master: add field to User and new class"
>
> git merge feature
> echo
> echo "==== merged, user_method into NoMethod class ===="
> cat models.py
> ```
>
> Actual Result
>
> After the merge, the user_method ends up inside the NoMethod class,
> which is incorrect and unexpected.
>
>
> Please let me know if any additional information is needed. Thank you
> for your time and help.
I think this is very much expected, unfortunately. Git is language
agnostic in the sense that it does not know the meaning of the
contents of the file it is thrown at. With the merge, what it was
asked to do is:
- The other branch, "feature1", added three lines, an empty
user_method() definition and a blank line around it, before
lines that have 'class product:' and ' id = 0' (or after lines
that have 'class User:' and ' name = str' followed by a blank
line).
- In the meantime, you added some stuff in feature2.
- Please replay what the other branch did on top of what we have.
But after your feature2, the precontext lines that it can use as an
anchor no longer exist (the blank line after 'class User:' and '
name = str' is gone). while the post context lines ("blank followed
by 'class Product: followed by 'id = 0'") are still intact.
Wiggling the added three lines there would be a more natural choice
than having to deal with "bugger = 'fix me'" whose disposition is
totally unclear to unthinking non-mind that is a mechanical merge
machinery in Git.
next prev parent reply other threads:[~2025-04-15 13:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-15 12:23 git merge bug report mu gsh
2025-04-15 13:52 ` Junio C Hamano [this message]
2025-04-15 14:13 ` Lucas Seiki Oshiro
2025-04-15 16:20 ` mu gsh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqtt6po7lj.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=yue937@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox