{"thread":{"id":"54514","subject":"No warning when checking-out a branch with a file that already exists but is not indexed in the current branch","startedAt":"2020-10-27T13:03:54Z","lastAt":"2020-10-27T13:03:54Z","messageCount":1,"participants":["Baptiste Fontaine"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"408505","messageId":"ED4DFC77-2135-476E-AA22-7E887B25565D@ptistefontaine.fr","threadId":"54514","inReplyTo":null,"subject":"No warning when checking-out a branch with a file that already exists but is not indexed in the current branch","fromName":"Baptiste Fontaine","fromEmail":"b@ptistefontaine.fr","sentAt":"2020-10-27T12:39:16Z","receivedAt":"2020-10-27T13:03:54Z","isPatch":false,"sender":{"key":"b@ptistefontaine.fr","avatar":null},"body":"Hello,\n\nI’m not sure if this is a bug or expected behavior:\n\n1. Create a sample repo:\n\n  % git init\n  % touch a.txt\n  % git add a.txt\n  % git commit -m \"add a.txt\"\n\n2. Create a new branch, in which you add foo.txt:\n\n  % git checkout -b devel\n  % echo \"Something\" > foo.txt\n  % git add foo.txt\n  % git commit -m \"Write something in foo.txt\"\n\n3. Go back to the first branch and create an ignored file with the\n   same name:\n\n  % git checkout master\n  % echo foo.txt > .gitignore\n  % git add .gitignore\n  % git commit -m \"ignore foo.txt\"\n  % echo \"Something else\" > foo.txt\n  % cat foo.txt\n  Something else\n\n4. Check-out the branch with the indexed file:\n\n  % git checkout devel # <-- no warning here\n  % cat foo.txt\n  Something\n\n5. Check-out again the branch without the indexed file:\n\n  % git checkout master\n  % cat foo.txt\n  cat: foo.txt: No such file or directory\n\nThe non-indexed file is now gone, and there was no warning when git\n“took over it” in step 4. As far as I know there’s no way to retrieve\nthe \"Something else\" content.\n\nI’m using git version 2.28.0.\n\nI came to this situation on a repository in which I had a ROADMAP.md\nfile on master, which I `git rm --cached` and added to .gitignore on\ndevel. I later modified this file, but it was removed when I switched\non master.\n\n\nRegards,\n\nBaptiste Fontaine\n"}]}