1

I have gone to do a push to a new repository, and accidentally set the old folder i was working on as the main folder for the new repository on github. Github Desktop did a pull of the old files and overwrote my entire folder, months of work gone. Is there a way to get back what the pull overwrote?

This is months of work down the drain because of one simple click.

When i clicked on the 'change directory' i chose the existing folder i was using with my main files, those files have been deleted where they didn't match and now it's a copy of a folder from months ago, that was pushed to github. Seemingly destroying all the work i had done.

Operating system is OSX 10.15.2

matt
  • 515,959
  • 87
  • 875
  • 1,141
learncodes123
  • 371
  • 3
  • 16
  • On my computer i had a folder (local), now it's done a pull of something older (repository remote) and over written my local folder. Unlike normal undo in OSX it wont undo anything, they're just gone. – learncodes123 Jan 28 '20 at 01:58
  • You edited your original comment. Then said the above after i replied.... And yes to 1, 2 time machine didn't back it up. – learncodes123 Jan 28 '20 at 01:59
  • OK but hold on. You say you were intending to push to remote B. So in preparing for that, did you commit? You must have, or there would be nothing to push. (And also you probably wouldn't have been able to pull, unless you committed first.) Well, so if you committed, then everything is still there in your repository — no problem. That, after all, is what a commit is (and what git is). – matt Jan 28 '20 at 02:17
  • So, i wanted to push the local files to a new branch, doing so it asked me if i wanted to change the folder for the remote branch, the branch was still on a very old branch, clicking yes, it overwrote all the local files on my computer, now it is a mirror of the remote branch from months before. The time machine backup issue seems to have been a bug with Catalina of which i just got unlucky. There was no new commit to the new branch i wanted, it did a pull from the old branch, overwriting the local backup i had. – learncodes123 Jan 28 '20 at 02:38

1 Answers1

0

Recovering files in a Git repository would only be possible if:

  • they were added to the index (complex but possible)
  • they were committed (git log or git reflog would show you the last commit)

Beside that, only time-machine (not an option in your case), or the local history feature present in some IDE might give you a chance of restoring (some or all of) those files.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Yes unfortunately i got incredibly unlucky with Catalina + this simple mistake of letting Github overwrite the folder. – learncodes123 Jan 28 '20 at 06:49
  • Yes it was, i dragged the folder with my files, onto the github app, where the new branch was, it asked 'do you want overwrite your current stash', i didn't think and pressed ok, it overwrote my folder with the files that were to be pushed, with files from a different branch, and now they seem long gone. No matter what i do to find them, they've been overwritten. – learncodes123 Jan 28 '20 at 07:30
  • 1
    @learncodes123 I see. This is why I usually use the command line instead of a gui. – VonC Jan 28 '20 at 07:31
  • Lesson learned, didn't realize it was so easy for git to blow away files. – learncodes123 Jan 28 '20 at 07:32
  • 1
    @learncodes123 not so much Git itself, but a GUI client (like GitHub Desktop), yes. – VonC Jan 28 '20 at 07:33