1

I'm not quite sure how it happened (bit of an amateur when it comes to git) but somehow, after executing git init, my entire desktop was deleted (lots of files). I've tried lots of suggestions from Google searching, such as "git reset --hard refs/original/refs/heads/master" and whatnot, but it always comes back with errors. I've tried listing branches, checkout, and log, but they all don't return anything...? I'm completely lost- I just want my files back. I'm not sure if they were deleted or moved.... I currently have around 60GB of free space, but I cant remember what I had before the accident- I know I had somewhere around 40 within the past few days, so maybe it's gone? I'm not sure if I remember cleaning up any space recently. If it matters, I'm on a Mac.

Edit: Here is just about everything (commands seemingly involved with this, a link to the program I was installing, and its build.sh) It seems that it was not git init, but rather something because of an error with build.sh? https://docs.google.com/document/d/1_NH1iDkHP6u5PTUYtxbCMJDB8MMqNCUdhnD4yXk3F6E/edit?usp=sharing

A. Bradley
  • 15
  • 5
  • `git init` doesn't remove files. It only creates a folder called `.git` with files it needs to do its job. Something else must have happened to things. I know it might be silly, but do you get anything when you run this in terminal? `ls -a ~/Desktop` – TheBeege Mar 27 '19 at 03:27

1 Answers1

1

Git init should not delete anything, it creates a new folder called .git in whatever directory you execute the command from. Now what it shouldn't do doesn't help you much, considering SOMETHING happened, but I'm 99% sure that nothing was actually deleted as the git init command does not have any calls to delete files. Even if you git init inside a directory full of files, it just initializes that .git directory. Now, my one and only guess would be, maybe somehow your desktop's files got put inside that .git directory (which is a hidden directory by default), and that all your files are there, just hidden. If you are on a Unix system, could you please try a ls -la while on /Desktop and see if there is a hidden .git directory with anything in it. On a Windows system, you can start typing "Show hidden folders" into the start menu and it should give you an option to see all hidden folders (then check same as above, if a hidden .git folder exists anywhere on/near desktop that contains all your files. git init should not move anything either, but maybe something went wrong?

Edit: So here's what went wrong to my best guess...

git init was done in the directory of '~/', this repo 'waifu2x-mac' was cloned/downloaded to desktop. Build.sh was run from a terminal from the location of 'Desktop/waifu2x-mac,

  • the first line of the script CDs to the directory of the script
  • it then does some stuff to see if there are any untracked files in the current directory (which was location of build.sh)
  • because nothing was tracked, as it was a new clone of the repo, it deleted everything in the current directory (/Desktop/waifu2x-mac)
  • This included the build.sh file that was currently running, as well as everything involved with that.
  • It then tries to CD into /Directories which doesn't exist, which triggers a fail on the script.
  • ??? happens and it now considers the git repo located at '~/' the git directory that this script was run from
  • The script then executes it's fail condition command, which is git clean -dffx

in essence, this is running rm -rf but just for all untracked files in the current git directory which is everything inside '~/'. the -d specifies all directories, and the 'ffx' is pretty much saying 'force remove everything including anything that is gitignored.' Git clean is unfortunately not undoable, as it doesn't track any changes.

at this point, you have limited options, with no guarantees. Check out this link and try some of the suggestions listed there (like extundelete and the USB recovery tool) Can I undo a `git clean -fdx`?

Best of luck to you- when all this is done, I would definitely go open an issue on that waifu2x-mac's Repo, and link this question in the issue. Even with user error involved, there should never be an issue where a program has autonomy to RECURSIVELY DELETE EVERYTHING unrelated to it, especially on a fail condition. (also why it reverted to the parent git repo and chose that location to delete from is beyond me...)

Also my comment below about git not having any commands to delete files was utterly wrong, and i am well aware of that.

Dsabadash
  • 445
  • 1
  • 4
  • 12
  • They said they were on a Mac – TheBeege Mar 27 '19 at 03:42
  • Which is a Unix based system, including answers on where to find the hidden folders section on windows is for if anyone else runs into this problem – Dsabadash Mar 27 '19 at 03:55
  • Checked hidden files- infact, I've tried checking every .git file I could find on my system (I seem to have created 2 or 3 within all of this) but none on the desktop. when it all happened, it warned me that it would be moving a bunch of files related to what I was installing, but nothing to do with my desktop files. I typed "y" to confirm and BAM my desktop wiped. – A. Bradley Mar 27 '19 at 04:23
  • Honestly, the only thing i know of that can reproduce this is by running 'rm -rf' from the command line while in the desktop. Git in itself has no commands to move or delete files (unless you count copying to/from a remote). do you still have access to the terminal window that ran the command? (i.e it's history) if so, can you either post it here or somewhere and drop a link to it? if not, you should at least be able to open a new terminal window and press the UP arrow key to scroll through previous commands issued, and could you please do the same and drop a link here. – Dsabadash Mar 27 '19 at 05:04
  • Sorry, I missed the Unix bit of the answer – TheBeege Mar 27 '19 at 05:41
  • @A. Bradley - You hit "y" to confirm something? It sounds like you did something that wasn't `git init`. Try running `history` and see if you can identify where things might have gone wrong. – TheBeege Mar 27 '19 at 05:42
  • Here is just about everything (commands seemingly involved with this, a link to the program I was installing, and its build.sh) It seems that it was not git init, but rather something because of an error with build.sh? I will update the question. https://docs.google.com/document/d/1_NH1iDkHP6u5PTUYtxbCMJDB8MMqNCUdhnD4yXk3F6E/edit?usp=sharing – A. Bradley Mar 27 '19 at 14:39