git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Merging adjacent deleted lines?

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 21, 2009, 21:08 UTC
Message-ID
<7vy6x4cqq1.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<57518fd10901211120n62f8d0e9ya8595fc9baa6476c@mail.gmail.com>
Jonathan del Strother <maillist@steelskies.com> writes:
Show 28 quoted lines
> Say I have a file that started out with the following content :
>
> line1
> line2
> line3
> line4
>
>
> I create a branch, which deletes line2.  Someone else's branch deletes line 3.
>
> When I merge those two branches, the conflict looks like :
>
> line1
> <<<<<<< HEAD:lines
> line3
> =======
> line2
>>>>>>>> SomeoneElse:lines
> line4
>
>
>
> Which in my cursory overview, looked an awful lot like the obvious
> merge resolution ought to be
>
> line1
> line3
> line4
Why?  The obvious resolution would be:
    line1
    line4

as it is obvious that you do not want line2 and the other does not want line3.

But that is only true if it is obvious to you. When you cannot remember what each side did since they forked, there are two ways you can use to understand the history better without resorting to graphical merge tools.

  $ git log -p --merge <path>

which shows you the commits involved in the conflict, what they did, and why they did what they did (of course, this assumes that your project participant did their commits properly).

  $ git checkout --conflict=diff3 <path>

This will add an extra block to the conflicted output to show the common ancestor's version, after showing yours. The conflicts left in <path> would look like this:

    line1
    <<<<<<< ours
    line3
    |||||||
    line2
    line3
    =======
    line2
    >>>>>>> theirs
    line4
which may make it clearer that you deleted line2 and they deleted line3.
Previous: Robin RosenbergNext: Jonathan del Strother
Message 3 of 9 in “Merging adjacent deleted lines?”
  1. Jonathan del StrotherJan 21, 2009
  2. Robin RosenbergJan 21, 2009
  3. Junio C HamanoJan 21, 2009
  4. Jonathan del StrotherJan 22, 2009
  5. Robin RosenbergJan 22, 2009
  6. Jay SoffianJan 23, 2009
  7. Robin RosenbergJan 23, 2009
  8. Jay SoffianJan 23, 2009
  9. Jay SoffianJan 23, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.