[BUG] "git checkout BRANCH -- FILE" deletes staged commits
- From
- Tasnad 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!?'