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

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

From
Luke San Antonio <lukesanantonio@gmail.com>
Date
Aug 8, 2013, 07:07 UTC
Message-ID
<CAP+CFTZWzoAg=ni6t1aif-85y6W4-2JUT4wooapTvD0oGH+HRw@mail.gmail.com>
Hi, my name's Luke!

Today, I had a problem merging a stash after immediately creating it. This is exactly what I did!

git stash save --keep-index git stash pop

And BAM! Merge conflict! This was especially weird because my file had this in it (taken directly from my code!)

<<<<<<< Updated upstream
     *
     * It should be used and passed along to member objects by GameStates!
     *
=======
     *
     * It should be used and passed along to member objects by GameStates!
     *
>>>>>>> Stashed changes
They are exactly the same!

Oh, by the way, I should mention that I did not edit any hunks to get the index the way I wanted it, I have read that doing that causes merge conflicts similar to this!

Then I got a hunch! I realized that git will refrain from applying a hunk if it finds it already was applied exactly (that's correct right?)... So I thought, maybe the patches are similar (represent the same changes) but aren't *exactly* the same.

I was right!
After saving the stash I take a look at the diff: (git stash show -p)
     /*!
-     * \brief The default font renderer, global to all who have a pointer to
-     * the Game class.
+     * \brief The font renderer implementation, obtained from the config file.
+     *
+     * It should be used and passed along to member objects by GameStates!
      *
-     * It need not be used at all!
+     * \note It can be cached, but not between GameStates, meaning it should be
+     * cached again every time a new GameState is constructed!
      */
After that, I take a look at the diff in my index: (git diff --staged)
     /*!
-     * \brief The default font renderer, global to all who have a pointer to
-     * the Game class.
+     * \brief The font renderer implementation, obtained from the config file.
      *
-     * It need not be used at all!
+     * It should be used and passed along to member objects by GameStates!
+     *
+     * \note It can be cached, but not between GameStates, meaning it should be
+     * cached again every time a new GameState is constructed!
      */
Aha! A difference, a difference so tiny it went unnoticed by me, but not by git!
Now the housekeeping:
What I wanted to do:
Apply a stash on top of a 'kept' index.
What I did:

git stash save --keep-index git stash pop

What I saw happen:
A merge conflict between the same changes (see above).
What I expected to see:
No merge conflict.
How are these different:
The conflict, which shouldn't happen since the changes introduced were the same!
-------------------------------------------------

It seems to me like the stash command is using a slightly different diff algorithm... Can anyone explain to me what's going on under the hood so I can understand this subtle difference? Does anyone know?

Thanks in advance, I'm sure you all will be very helpful!
- Luke
Next: Phil Hord
Message 1 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.