3

I had already tracked files that I wanted to add to the .gitignore file (e.g. App.config), so I followed the advice of this post (and others like it), and did the following:

  1. ran git rm --cached *.config
  2. added *.config to my .gitignore file
  3. git added and commited the ignore file and the "deleted" files

After doing the App.config file, I double checked, and the file was there, with the little symbol for "ignored" next to it in Visual Studio. Everything seemed peachy, so I did this for several files every few commits as I came across other things I thought should be added to the .gitignore, including *.csproj (which I now regret very much).

It was all fine until today when I had to switch to the master branch for a moment, and the project (my dev branch) had to be reloaded. The load failed and when I tried to re-load, it said :

The project file <missing file.csproj> has been moved, renamed, or
is not on your computer.

Lo and behold, all the files I had untracked are now gone when I search in file explorer.

I've been going back through commits, and the "missing file" error goes away before that file was "removed from the cache" (aka deleted, even though it wasn't deleted after I committed it, since I've been working in it without issue until now). I'm stumped as to why git deleted these files.

If anyone has advice on a solution, I'm all ears; the current plan is to copy the code I've changed on this branch and restart on a new branch from master, but I'd rather not have to redo everything I've been working on the past couple weeks. Regardless, my main question is why this happened in the first place so I can avoid doing it again.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • 1
    Git does not care about ignored files. Those are not in the history since you ignored them. What did you do so that the files disappeared? Did you re-clone the repository? – dan1st Oct 13 '20 at 05:10
  • 1
    I can easily see this happening if you go to a revision where the files are being tracked and then you go back to a revision where they are gone. Probably when you moved to the revision where the files were _present_ git warned you (or you did checkout -f). – eftshift0 Oct 13 '20 at 05:48
  • 1
    You can being them from a branch or revision where they are still present with chrckout `git checkout other-branch -- some-file` – eftshift0 Oct 13 '20 at 05:50
  • eftshift0's comment is your answer ; I ran a small test, and unfortunately, is seems that a regular `checkout` (without `-f`) will also accept to clobber your on disk file with its versioned version when you switch from a "gitignored" version to a "tracked" version. – LeGEC Oct 13 '20 at 07:35
  • Why did you need to ignore csproj file? That does not make any sense. Go back to your working branch, and remove `*.csproj` from `.gitignore`. Then add that project file to repository, and switch back to `master` branch. – kosist Oct 13 '20 at 07:37
  • Thank you, everyone, for your input. @LeGEC So forcing checkout of master branch would cause the removal of files in the dev branch? I know I didn't use -f, but I may have accidentally done the checkout in the command line while VS was still open, so maybe that was the issue. – breadboardwoman Oct 13 '20 at 18:32
  • @kosist I see that you're right. I added it because I read somewhere that you could include it. It was a dumb mistake I guess. – breadboardwoman Oct 13 '20 at 18:34

0 Answers0