Can I salvage my local repo after the mistake of adding .Rproj, .Rdata to .gitignore

Today I had RStudio and Github Desktop open simultaneously, not thinking about what could go wrong if I did something dumb. I did a dozen or so commits on a project with a couple of branches, master and branch2. Within the last few commits I made, changes included the idiotic move of adding .Rdata and .Rproj to .gitignore, because I didn't want that file pushed to public remote repo. Somewhere around those commits (which I pushed to remote) I experienced an unusual and serious problem: large numbers of files that only ever existed on branch2/Applications went missing. Some (a small percentage) showed up on master/Applications, even though master/Applications never existed before today!

I completely forgot how RStudio and version control are intimately tied up with R projects. RStudio was open this whole time I was modifying .gitignore and using Github to switch back and forth between branches.

I'm looking for someone with a good grasp on the way RStudio requires projects for version control use, so I can describe further details to them and hopefully get me on a path to solving a mess that I do not know how to deal with.

Note -- all this is local, and I never committed or pushed the branch2/Applications folder, so I do not have a backup. Like I said, most of them just seemed to have disappeared. Fortunately they are not mission critical files, but boy it would help to have them back.


I'm quite sure I don't follow everything you say. But regardless all is probably not lost.

First -- and the least important thing -- is that I think you can set aside concerns about special interaction between RStudio (Projects) and Git. And RStudio Project is a folder on your computer. A Git repo is a folder on your computer. And sometimes or often they coincide. But Git won't behave any differently for a folder that is or is not an RStudio Project. I regularly work on the same repo from RStudio, the shell, and a Git client called SourceTree.

More importantly, anything you have committed to a local branch can be recovered from the ref log. I won't say this is easy or enjoyable, but it's there somewhere. It sounds like you likely have these commits (and earlier) states present both locally and perhaps even remotely, so I'm optimistic that you'll be able to checkout a version of the missing files from some previous commit.

You'll have to do some googling / stackoverflowing but here's a start:

That said, the only catastrophic data loss I've witnessed was also with GitHub Desktop. And for that reason I don't recommend it. I hypothesize that it hides so much of the Git machinery that it somehow makes it easier to do dangerous things.

Thank you for all the tips and encouraging words. I have done some more reading / SO'ing and I also believe there are some simple things I can try to see if this stuff is recoverable. I'm such a beginner with git I'm to going to clone the repo to test the actions first.