-2

So my teammates had set up a git repository and all of us were supposed to push our own respective works to our own separate branch.

Difference is, everyone used the Desktop app while I tried to use the CLI to create a new empty branch and push to it but instead it deleted everything under my assets folder!!!!

I followed this to create an empty branch: Create empty branch on GitHub where in it says to use:

git switch --orphan <new branch>

which I did.

I initialised a new local git repository, set the remote origin, did the switch orphan command above, committed, and pushed. When I then went to check Github if the files are uploaded properly, I saw that it was only partially uploaded. Specifically, only the non-important files. I then got confused so I went back to check at my original files only to then find out that they're GONE.

Please somebody help.... That was a month's worth of tireless day to night work...

I'll include a log of the terminal here: https://gist.github.com/NicholasSebastian/b5dceb995e5a33922df8fbeb99f03652

  • 4
    [Under what circumstances may I add "urgent" or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) – evolutionxbox Aug 24 '22 at 08:02
  • 1
    That gist is 10k lines long Please replace the gist with the relevant parts directly in the question. Also, don’t panic:`git reflog` is _probably_ all you need to look (and maybe add to the question if that doesn’t allow you to self-solve) to find your missing files – AD7six Aug 24 '22 at 08:17
  • 2
    Was that Unity3D tag really necessary? – Shrimp Aug 24 '22 at 08:22
  • 1
    It looks like you are using _Git Large File System (LFS)_, an extension to Git for handling large files. Since you used the command line, performing a `git pull` will **not** by default perform a `pull` of LFS files. Just type in `git lfs pull`. Also, since you **are** using Git LFS I highly recommend you use a Git GUI client as they will automatically handle all the LFS stuff for you. This is vital when using a Git LFS repo with apps like Unity, Unreal, Photoshop etc. If you don't, apps like Unity will think **you deleted stuff!** –  Aug 24 '22 at 08:27
  • 1
    _"That was a month's worth of tireless day to night work"_ - why did you wait a month to push your work to the remote? I like to commit at the end of the day where my CI server checks that it can compile it and that I haven't forgotten to add something. –  Aug 24 '22 at 08:33

1 Answers1

2

Ok after all that panicking, reading through a ton of git documentation and other blogs and sites revealed that I can list all changes on the git repository with:

git reflog

where it shows all the changes and its corresponding SHA reference values.

I can then use the git reset --hard command to replace the current directory with the state it was at a given SHA reference point:

git reset --hard <SHA value>

I'm glad I finally got all my files back at least after all that panic and stress.
Lesson learned the hard way: Back up all your files.