1

I recently wanted to start tracking some project files for a certificate course I'm taking, so I got the Git Desktop app and linked my main project folder to my Github repo, where I intended to only track specific folders.

So thinking this was the right way to go, I added basically everything that I didn't want to track to the .gitignore file.
All these Jupyter Notebooks, tens of thousands of data images, etc.

And after one night, and one pull to get the readme from the online repo into my local files, Git deleted every single file that was named on the .gitignore file.
Every folder is empty, except for the tracked project folders.

Is there a way to recover the files, and prevent this from occurring in the future?

Community
  • 1
  • 1
  • If those files *were* tracked and committed, and you added them to `.gitignore`, this gives Git permission to *delete* the files. The committed versions *of* those files remain in all the existing commits that have them, so you can retrieve those versions from those old commits. Note that the tracked-ness of any given file is a changeable state. If file F is currently tracked, and is in the current commit `a123456` for instance, and you have Git switch to some other commit `b789abc` in which the file *does not* exist, Git needs to remove the file from your working tree. – torek Apr 22 '22 at 07:17
  • Git *will* remove the file before switching commits, but will refuse to switch *to* the other commit if the file is "dirty" (contains content that was not saved in the commit) *unless* the file is listed in `.gitignore`. – torek Apr 22 '22 at 07:18
  • Note that Github Desktop is not *Git* (these are two entirely different programs) so GitHub Desktop may not have the exact same behavior *as* Git here, but it's likely that they behave very similarly. You tagged your question with [tag:git] and not [tag:github-desktop] so you get Git answers, not Github-Desktop answers. – torek Apr 22 '22 at 07:20
  • Related question: https://stackoverflow.com/questions/51516776/git-pull-origin-master-deleted-hidden-files-from-gitignore – JaBe Apr 24 '23 at 09:15

1 Answers1

0

That would be the same as git clean -X, and I don't see why GitHub Desktop would ever execute that.

Check the logs of GitHub Desktop to confirm if those deletions are coming from this application.

But regarding non-tracked deleted elements, there is not much beside file recovery utility, as detailed in "Can I restore deleted files (undo a git clean -fdx)?", or on your IDE.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250