Search code examples
atlassian-sourcetree

Clicked reset branch to current commit and lost all my work, what the heck have I done?


I am brand new to Source Tree and have no idea what Im doing but I hope I didn't just lose my work.

I clicked a button that says reset branch to current commit, and chose the "Mixed" Option. I then pushed my files. But after going back into UE4 (a program Im tracking) I noticed that my files have gone back a really long time. I can see all the files I have in the "Working Copy" section of source tree, but all of them say "Missing" and am too afraid of doing anything in fear of losing it all. I need help on what button to press to undo my changes (CTRL Z DOESNT WORK :( )

Here are some pictures of where I am.

enter image description here

If it says "Working Copy" and I am able to click "Open Before" I assume the files still exist, I hope.

If I can, how do I get my Files back to the way they were before I messed up.


Solution

  • If you committed the changes before using the reset branch, the changes are not lost.

    I'll explain this using command line commands, but I guess there are advanced GUIs that can achieve the same thing.

    Open a command line interface of your choosing that has access to git commands, then navigate to the project folder

    $ cd /path/to/project/root
    

    Next, check the git reflog

    $ git reflog
    
    874333c HEAD@{0}: reset: moving to 874333c
    5dc3401 HEAD@{1}: commit: committed something awesome
    4ef6395 HEAD@{2}: commit: fixed bug related to ballistics computation
    d5cb3b3 HEAD@{3}: commit: added ballistics computation
    

    What you want to do now is to reset your branch again, but this time to the state it was in before (ie. 5dc3401) you did a reset to the current state it's in

    $ git reset 5dc3401