git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luke San Antonio <lukesanantonio@gmail.com>
To: git@vger.kernel.org
Subject: [Bug] git stash generates a different diff then other commands (diff, add, etc) resulting in merge conflicts!
Date: Thu, 8 Aug 2013 03:07:23 -0400	[thread overview]
Message-ID: <CAP+CFTZWzoAg=ni6t1aif-85y6W4-2JUT4wooapTvD0oGH+HRw@mail.gmail.com> (raw)

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

             reply	other threads:[~2013-08-08  7:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-08  7:07 Luke San Antonio [this message]
2013-08-08 20:54 ` [Bug] git stash generates a different diff then other commands (diff, add, etc) resulting in merge conflicts! Phil Hord
2013-08-12  5:29   ` Luke San Antonio
     [not found]     ` <CABURp0rWMAs9vT791vp4BEYS-Y9Jmzjmt4bbuB+po8=vkiqUWQ@mail.gmail.com>
2013-08-13  5:31       ` Luke San Antonio
2013-08-16  0:05         ` Phil Hord

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='CAP+CFTZWzoAg=ni6t1aif-85y6W4-2JUT4wooapTvD0oGH+HRw@mail.gmail.com' \
    --to=lukesanantonio@gmail.com \
    --cc=git@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).