Reputation: 93
I just made a huge mistake with Git and I'm afraid I've just lost 2 days of work, am hoping one of you might be able able to help me undo that!
I'm new to Git, so I'm constantly looking online how to do certain things, a few days ago I created a new branch with the web interface, since I've worked and worked without committing or pushing (or checking out said branch) since, today I thought it was about time I pushed my work, so I did the following;
git add .
git commit -m "these changes were awesome"
Then before git pushing, I thought "I really should put this on a new branch" a quick Google search on "how to change branch" came up with "git checkout"... "ok great!" I thought, and like the ape I am did it without a second thought, to see my file structure in VS Code massively change... then I realised I had lost it all.
Is there any hope that Git stores these deleted files anywhere? Is there any hope that I can get these files back and not have to jump out my window?
Upvotes: 1
Views: 7910
Reputation: 93
I've marked @Daniiel Mohr's answer as correct because he helped me get there, but I'll post here the exact steps I used for others in my position,
git reflog
This gives you a log with your recent activity, look for your commit in a list like this:
f2ff96e HEAD@{3}: checkout: moving from multi_content_support to dynamic-contents
b6ebc14 HEAD@{4}: commit: FixedContainer and MutableContainer added with dynamic support, Image, Label, Button and TextInputField upgraded to dynamic
Find the id of your commit, in my case "b6ebc14"
Then use git reset with your id:
git reset --hard b6ebc14
et voilà, git will kindly stop your anxiety attack ;)
good luck!
Upvotes: 0
Reputation: 724
You added all your files, then committed them, so sounds like they're safely stored on your branch. How are you interacting with git (e.g. shell, git extensions, etc...)?
Run "git branch" if you're in the console. What do you see? If in git extensions or similar, what branches / commits do you see?
If you switched branches, you should be able to checkout the previous branch to see your committed work. Otherwise (if on current branch) carefully reset or stash changes on the current branch if you see your commit in the previous log ("git log" command).
Upvotes: 2