-1

I'm trying to learn git, I'm new. I got an error while performing a pull from xcode and it was said on the internet that the answer was git reset --hard. I also performed git init and "git reset --hard" from the terminal. As soon as I performed this operation, almost all my files on my desktop were deleted, including my word, excel files and videos in my documents. I want to know what could be the reason for this. I would be grateful if you could help.

Caleb
  • 124,013
  • 19
  • 183
  • 272
KYY
  • 1
  • 1
  • "it was said on the internet that the answer was" ... the answer to what? Tell us what exact commands you executed. – Romain Valeri Jun 16 '22 at 14:08
  • https://stackoverflow.com/questions/15745045/how-do-i-resolve-git-saying-commit-your-changes-or-stash-them-before-you-can-me My friend said try it by throwing this link, so I started to try it with confidence, how stupid I was, actually I was doing unrelated things. it happened after the "reset" command here. – KYY Jun 16 '22 at 14:43
  • Can you provide more info? What commands did you run, in what order, and where (on which directory) did you run them? – ParSal Jun 16 '22 at 15:04
  • Really sorry to say this, but it sounds like you ran a bunch of really powerful git commands from your home directory and may have deleted all its contents. If so, there may not be any way to recover unless you have a backup. It’s going to be really hard for us to track down what happened without the exact commands, but if you were running all of this from home instead of within the git dir it’s possible you just lost your whole user dir! – Michael Delgado Jun 16 '22 at 15:11
  • Of course, first I opened the terminal and typed the command "git reset --hard", then that didn't work so I entered the command "sudo git init" (M1 Mac) and ran the "git reset --hard" command again. All the files on my desktop were deleted in an instant, only my xcode projects remained. Deleted files did not go to trash. When I checked my documents, I saw that my files there were also deleted. I really can't understand, I had important videos and photos. I guess there's no way I can get them back. – KYY Jun 16 '22 at 15:17
  • @MichaelDelgado Thanks for your time, I guess I won't be able to find a solution :( – KYY Jun 16 '22 at 15:20
  • 1
    yeah I'm really sorry about that. you definitely want to be careful using terminal commands (esp ones with names like `--force` or `-r`, and *especially* with sudo). You executed a bunch of administrator-level delete commands and there's nothing apple can do to protect you from that. that's a tough way to learn that lesson! good luck :/ – Michael Delgado Jun 16 '22 at 16:05
  • Given that you have a mac, do you have Time Machine and/or iCloud backups of key files? That's the way to go here. – torek Jun 16 '22 at 19:58
  • Open your desktop in Finder, and press `Cmd + Shift + . (period)` (to show hidden folders). Do you see a folder named `.git`? If so, it might be possible to recover your files using `git reset`. Let me know, and I can help you further. – qitianshi Jun 17 '22 at 09:41
  • @qitianshi Thank you for your time. Yes, I found a .git file if that's the file you're talking about. Some files are empty, some are full. Like this, https://ibb.co/61h1kfn – KYY Jun 17 '22 at 10:36

1 Answers1

0

This is probably a duplicate of How to remove all local files that were accidentally added to the git system.

Basically, it seems you said git init when your terminal's current directory was your Desktop. Therefore, you accidentally placed your entire Desktop under Git control — and thus, if you proceed to give "dangerous" Git commands, such as git reset or git clean, you risk serious damage to your Desktop.

You did give a dangerous Git command; git reset --hard is an extremely dangerous command. It means, "Force my working tree to consist of exactly what the most recent commit consists of." All files in your working tree that are not part of the most recent commit are thus deleted. But in your case, the Desktop was the working tree! Thus you wiped out your entire Desktop.

If you have not previously done an add-and-commit of all the files on the Desktop (and it sounds like you haven't), those files are now totally gone. There might be copies in a backup that you've made in some other way, but that would have nothing to do with Git, which has done exactly what you (unfortunately) asked it to do.

matt
  • 515,959
  • 87
  • 875
  • 1,141