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
Luke San Antonio <lukesanantonio@gmail.com>
Date
Aug 12, 2013, 05:29 UTC
Message-ID
<520872CC.3040507@gmail.com>
In-Reply-To
<CABURp0oATJ58POmgYLjSmy-y84LTjkP0PTh4=3M-vc04_AoMdg@mail.gmail.com>
On 08/08/20130 04:54 PM, Phil Hord wrote:
Show 19 quoted lines
> Luke,
>
> I think the issue is that your working directory receives your cached
> file when you say 'git stash --keep-index'.  When you restore the
> stash, your previous working directory now conflicts with your new
> working directory, but neither is the same as HEAD.
>
> Here's a test script to demonstrate the issue, I think.  Did I get
> this right, Luke?
>
>   # cd /tmp && rm -rf foo
>   git init foo && cd foo
>   echo "foo" > bar &&  git add bar && git commit -mfoo
>   echo "bar" > bar &&  git add bar
>   echo "baz" > bar
>   echo "Before stash  bar: $(cat bar)"
>   git stash --keep-index
>   echo "After stash  bar: $(cat bar)"
>   git stash apply

Actually no, in your script, the bar file has a modification in the working tree which is in the same hunk as a change applied to the index. In my project the changes that were added to the index are not modified further in theworking tree.

--------

Not only that, but I found out why git was generated different patches! I realized that when I removed a hunk appearing before the merge conflict from the working tree and index, the merge conflict disappeared! Turns out, we can forget about stashing for a minute! First the hunk in my working tree:

@@ -56,12 +56,14 @@
      bool running_ = true;

      /*!
-     * \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!
       */
-    std::unique_ptr<FontRenderer> font_renderer_ = nullptr;
+    FontRenderer* font_renderer_ = nullptr;

      int run(int argc, char* argv[]);

Most of this is unimportant, but notice the line number spec:@@ -56,12 
+56,14 @@
The line number of this hunk doesn't change! Then I addeda few lines *above*
this hunk, (around line 30 I think). Here is the diff again:

@@ -56,12 +58,14 @@
      bool running_ = true;

      /*!
-     * \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!
       */
-    std::unique_ptr<FontRenderer> font_renderer_ = nullptr;
+    FontRenderer* font_renderer_ = nullptr;

      int run(int argc, char* argv[]);

Notice the new line number spec:@@ -56,12 +58,14 @@

It moves two lines down, because I added those two lines before it, 
makes sense!
But also notice that the patches are different, just because of the two 
lines
above it!

I thought I might be able to fix this problem by changing the new 
diff.algorithm
config option to 'patience', but it seems to only affect how patches 
look, not
how they are stored internally... Same problem!

Also, I'm wondering why that line was picked up by git if the patches 
don't match,
shouldn't git give me a conflict with the whole hunk, or is the system 
smarter
than that?

What if merging suppressed the conflict if both possibilities are the 
same? Isn't
that reasonable, or is there some 1% where this could cause (silent but 
deadly)
data loss.

Sorry, I'm just rambling...

Anyway, thanks for your help Phil!
- Luke
Previous: Phil HordNext: Luke San Antonio
Message 3 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.