Ron
Ron

Reputation: 513

Restore local uncomitted changes in git

I've been working locally on a project, and once I was ready to commit my changes I did the following:

git add .
git add -A
git commit -m 'commit message here'
git push

Next git asked me to pull from the repo to get up to date changes. The repo was currently empty, in a past commit I deleted all the files.

So when I did the pull it deleted all the project files.

Without thinking I did a git git reset HEAD@{1} to undo the pull. I have no idea what happen, I just want my uncomitted changes back. I have a copies of the project, but not my uncomitted changes.

I did another git reset HEAD@{1} -- and it listed the uncommited files

When I did git reflog it list my commit that did not go to my remote server. Is it possible to recover those files? Or get my repo back to that state?

In reflog, this is where I need to get back to: 12a467c HEAD@{7}: commit: latest version 2015

Is this possible?

Upvotes: 1

Views: 80

Answers (1)

Sam Varshavchik
Sam Varshavchik

Reputation: 118340

In reflog, this is where I need to get back to: 12a467c

Well, then:

git checkout 12a467c

This will place you in that commit. At this point, you need to figure out how to recover your branch. Before contemplating the next step, you should do a

git checkout -b recovered-lost-branch

So it won't get lost, and you can switch to your branch, and figure out what to do next.

Upvotes: 2

Related Questions