3

From git gui, I used gitk to git reset -hard to a few commits before my current one, as I needed to test if everything was working before the changes.

Since I even had a few uncommitted changes, I git stash in order to save them and being able to reapply them once going back to my last commit.

The problem is that gitk is not showing the top of my commit tree any more (the top commit is the current one and I don't see any commit above it)

It was sometimes since last time I used git, but I thought I can use git reset -hard to bring the current code to a previous version, and then git reset -hard to the old version.

How can I retrieve all the commit between the old HEAD and the revision I git reset -hard to? Please tell me there is some kind of way.

I'm using Eclipse as development tool (in case I'll need to use it's cache)

Makers_F
  • 3,033
  • 4
  • 36
  • 51

1 Answers1

5

What you did could work if you had first make a new branch, before the first git reset --hard.

Because git reset moved your current branch back, and those commits are no longer referenced by any branch (and not visible anymore)

You need to fallback to the command line, and try a:

git reset --hard ORIG_HEAD
# or
git reset --hard HEAD@{1}

ORIG_HEAD or HEAD@{1} should have the SHA1 you were before the first reset.
If not, git reflog can help (that is what HEAD@{1} should be listed in).

Not, as alluding to in "ORIG_HEAD and FETCH_HEAD from history view in Eclipse", you should be able to see ORIG_HEAD in the "History view" of Eclipse.

Oboe
  • 2,643
  • 2
  • 9
  • 17
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • It worked. Thank you. I was so scared I lost all the work. It was pretty dumb of me to do such a thing before double checking what the command do. I still can't accept your answer, but the moment the 10 minutes limit expires I'll do so. Can you suggest we what command should I use in future to bring the current code to a previous state? Should I branch, reset and then delete the branch? – Makers_F Nov 08 '14 at 12:10
  • Bringing the current to a previous state is best done by making and switching to a new branch (even a temporary one): http://wiki.eclipse.org/EGit/User_Guide#Branch_Creation_Dialog – VonC Nov 08 '14 at 12:12
  • Checking `git reflog` should be done before doing a `git reset --hard HEAD@{n}`. That way you're sure which reference you really want. – jcm Nov 08 '14 at 12:38