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

BUG? git stash and immediate git apply results in conflict

From
AVAkos Vandra-Meyer <axos88@gmail.com>
Date
Jun 1, 2022, 06:55 UTC
Message-ID
<CAHHcNoe12h5E9OmkZy03-i7miFg2hLiT04BF3_t9C2bcmduR5Q@mail.gmail.com>
Hello!

I believe there might be a bug in how a git stash is calculated with the -k flag. I would expect to always be able to stash and pop a set of changes, but if the working directory contains staged and unstaged changes for a file, this results in a conflict.

The stashed diff shows the changes from the last commit, rather than what is in the current working directory, so when the stash is applied it results in a conflict, because there are staged changes in the current working directory.

Steps to reproduce:
 mkdir test
 cd test
 git init .
 echo foo > a
 echo bar >> a
 echo baz >> a
 git add a
 git commit -m "initial"
 cat a | sed s/bar/foo2/ > a2; mv a2 a git status
 git add a
 cat a | sed s/foo2/xxx/ > a2; mv a2 a
 git status
 git stash -ku
 git stash pop
Thanks for looking into this,
  Akos Vandra-Meyer
Next: Chris Torek
Message 1 of 4 in “BUG? git stash and immediate git apply results in conflict”
  1. Akos Vandra-MeyerJun 1, 2022
  2. Chris TorekJun 2, 2022
  3. Akos Vandra-MeyerJun 2, 2022
  4. Chris TorekJun 2, 2022

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.