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

Re: [Bug] git stash generates a different diff then other commands (diff, add, etc) resulting in merge conflicts!

From
Phil Hord <phil.hord@gmail.com>
Date
Aug 16, 2013, 00:05 UTC
Message-ID
<CABURp0qFnvW4X9MLhB=Q45S6xmV1HJ1-8NGRD7UyOLrLVxapvQ@mail.gmail.com>
In-Reply-To
<5209C4CD.8040607@gmail.com>

On Tue, Aug 13, 2013 at 1:31 AM, Luke San Antonio <lukesanantonio@gmail.com> wrote:

Show 6 quoted lines
>
> So I found an isolated case, it's very strange...
>
> Here's a script!
>
>
<deleted>
Thanks for that.  It was hard to read, but it demonstrates the problem well.
Show 8 quoted lines
> ... Copy and paste that into a terminal and you should have a recreated
> version of my repository there! Now that the file is partly stashed and
> partly in the index, check out the difference in diffs:
>
> try:
>   git diff --staged
> then try:
>   git stash show -p

This one is pretty sneaky. It is not limited to git-stash. I can demonstrate the problem now using 'git merge-file'.

But I can only make this problem show itself when:
   1. The collisions are separated by just one line of common code, and
   2. One of the lines of common code is duplicated in one of the
collisions, and
   3. The first two lines of the file are duplicated, and
   4. One of the first two lines is deleted on one side but not the other.
I have managed to boil the test down to this script:
    #-----------------------------
    cat >base <<base
        1 duplicate
        1 duplicate
        3 unchanged
        4 will change
        5 gets deleted
        7 duplicated
        8 will change
base
    cat >left <<left
        1 duplicate
        1 duplicate
        3 unchanged
        4 changed
        7 duplicated
        6 new line
        7 duplicated
        8 changed
left
    sed -e 1d left > right
    git merge-file -p left base right
    #-----------------------------
The result looks like this, showing the duplicate "collision":
  1 duplicate
  3 unchanged
  4 changed
  <<<<<<< left
  7 duplicated
  6 new line
  7 duplicated
  =======
  7 duplicated
  6 new line
  7 duplicated
  >>>>>>> right
  8 changed
But it should look like this instead:
  1 duplicate
  3 unchanged
  4 changed
  7 duplicated
  6 new line
  7 duplicated
  8 changed

A similar (but different) stupidity shows up if you remove line "3" from all three files.

I tested this in 1.6.5 and the same thing occurs there, so this is NOT recent regression.

Phil
Previous: Luke San Antonio
Message 5 of 5 in “[Bug] git stash generates a different diff then other commands (diff, add, etc) resulting in merge conflicts!”
  1. Luke San AntonioAug 8, 2013
  2. Phil HordAug 8, 2013
  3. Luke San AntonioAug 12, 2013
  4. Luke San AntonioAug 13, 2013
  5. Phil HordAug 16, 2013

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.