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

[BUG] "git checkout BRANCH -- FILE" deletes staged commits

From
TKTasnad Kernetzky <tasnadk@gmail.com>
Date
Nov 19, 2019, 17:10 UTC
Message-ID
<5cb30154-5753-f229-9fa2-6c82d2896abc@gmail.com>
Hi,

I suppose I found a bug in git version 2.24.0. Please consider the small shell script to reproduce.

Best,
Tasnad

#!/bin/bash # init repo, create master branch git init echo 'master' > tst git add tst git ci -m 'master'

# create branch "B" where tst contains the line from master plus a line "B" git checkout -b B echo 'B' >> tst git commit -am 'B'

# back in master: stage a change git checkout master echo 'master_dirty' >> tst git add tst echo '*** tst should contain [master, master_dirty]: ***' cat tst echo '-------------'

# checkout copies over contents from B -> I guess the bug is here, changes are not detected git checkout B -- tst git status echo '-> this seems to be wrong, change is not detected'

# if we now go to B and back to master, we loose staged changes echo '*** tst should contain [master, B]: ***' cat tst echo '-------------' git checkout B echo '*** tst should contain [master, B]: ***' cat tst echo '-------------' git checkout master echo '*** tst should contain [master, B]: ***' cat tst echo '-------------' echo '-> wrong / staged changes lost!?'

Next: Brandon McCaig
Message 1 of 2 in “[BUG] "git checkout BRANCH -- FILE" deletes staged commits”
  1. Tasnad KernetzkyNov 19, 2019
  2. Brandon McCaigNov 22, 2019

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.