0

I recently did a hard head reset, stupidly thinking I was resetting my Android Studio project to the earliest commit I made. I learned here I can undo the hard reset

What you want to do is to specify the sha1 of the commit you want to restore to. You can get the sha1 by examining the reflog (git reflog) and then doing

git reset --hard

But don't wait too long... after a few weeks git will eventually see that commit as unreferenced and delete all the blobs.

But I'm unable to use git reflog. I get thisn message when I run that command

bad default revision 'HEAD'

Community
  • 1
  • 1
the_prole
  • 8,275
  • 16
  • 78
  • 163
  • I'm not completely sure whether or not I understood your question, but If you are in your project directory you can easily run git branch , and you will see the branch which is already set. Alternative you can find your project directory by looking for any folder with .git inside. – David A Nov 13 '15 at 22:09
  • Correct me If I'm wrong, but I understood that to run git commands, my current directory had to be set to my local repo. Now when you say run git brach, is that somethin I can run from Android Studio? – the_prole Nov 13 '15 at 22:10

1 Answers1

0

Have you tried this command in the project directory ?

git fetch --all

Edit: Ok try adding your remote url first and then try to fetch everything.

git remote add origin git@github.com:username/reponame.git
Iulian
  • 1,156
  • 11
  • 19
  • Yeah, it doesn't do anything – the_prole Nov 13 '15 at 22:07
  • if type git fetch I get `No remote repository specified. Please, specify either a URL or a remote name from which new revisions should be fetched. ` – the_prole Nov 13 '15 at 22:08
  • Thanks, I must have used the wrong user name and respository, now I get `The authenticity of host 'github.com (192.30.252.131)' can't be established.` – the_prole Nov 13 '15 at 22:23
  • Run ssh github.com and type yes and it should fail. Then run your command again. If not try ssh github.com again as they have multiple IP's and you might need all of them. ( from http://stackoverflow.com/a/18712842/3935301 ) – Iulian Nov 13 '15 at 22:24
  • I can't run the same command again. I get `fatal: remote origin already exists.` and when I run `git remote -v` I see the username and URL. I can change url with `git remote set-url` but how do I reset username? – the_prole Nov 13 '15 at 22:28
  • I think a better solution for you will be to delete the .git folder from inside your project and try adding the remote again and fetch the code. – Iulian Nov 13 '15 at 22:31
  • I have looked for this folder, but I can't find it. – the_prole Nov 13 '15 at 22:33
  • It's normally hidden, you can use terminal ... rm -rf .git or if you are on Windows just show hidden files. – Iulian Nov 13 '15 at 22:36
  • Yeah, I don't know what I'm doing. Basically, I'm using android studio, and I did a hard head reset, and I want to revert that change. Any idea how to do that? – the_prole Nov 13 '15 at 22:45