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 8, 2013, 20:54 UTC
Message-ID
<CABURp0oATJ58POmgYLjSmy-y84LTjkP0PTh4=3M-vc04_AoMdg@mail.gmail.com>
In-Reply-To
<CAP+CFTZWzoAg=ni6t1aif-85y6W4-2JUT4wooapTvD0oGH+HRw@mail.gmail.com>

On Thu, Aug 8, 2013 at 3:07 AM, Luke San Antonio <lukesanantonio@gmail.com> wrote:

Show 12 quoted lines
>
> 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!)
>
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
The output looks like this:
$  git init foo && cd foo
Initialized empty Git repository in /tmp/foo/.git/
$ git commit --allow-empty -mInitialCommit
[master (root-commit) b5ecc7e] InitialCommit
$ echo "Bar" > bar &&  git add bar && git commit -mBar
[master 16d708b] Bar
 1 file changed, 1 insertion(+)
 create mode 100644 bar
$ echo "bar" > bar &&  git add bar
$  echo "baz" > bar
$  echo "Before stash  bar: $(cat bar)"
Before stash  bar: baz
$  git stash --keep-index
Saved working directory and index state WIP on master: 16d708b Bar
HEAD is now at 16d708b Bar
$  echo "After stash  bar: $(cat bar)"
After stash  bar: bar
$  git stash apply
Auto-merging bar
CONFLICT (content): Merge conflict in bar
Recorded preimage for 'bar'
$ cat bar
<<<<<<< Updated upstream
bar
=======
baz
>>>>>>> Stashed changes
Phil
Previous: Luke San AntonioNext: Luke San Antonio
Message 2 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.