2

i reset my head to a few commits back in android studio and chose reset type as hard. I lost a weeks work. Is there any hope to undo this ? I am using android studio and it has GUI built in options to do all git related functions so i never used git bash (or whatever terminal is used for git). There is a solution here but it used terminal so i asked again if anyone knows how to do it using android studio itself.

Community
  • 1
  • 1
Shreyans
  • 1,043
  • 2
  • 14
  • 25

2 Answers2

20

It's likely that you can use Android Studio's Local History to restore the changes. Right click the root directory of your project, select Local History | Show History... from the menu. In the history, you'll find an "External change" entry corresponding to the 'git reset' command that you performed. You can select the entry below that and press the "Revert" button.

yole
  • 92,896
  • 20
  • 260
  • 197
0

Read the full answer here - How to move HEAD (checkout, revet, reflog, reset):

Summary of the attached answer

(read it through to get a very detailed answer):


git checkout

git checkout <commit_id>

git reflog

You can always use the reflog as well

git reflog
git checkout HEAD@{...}

This will get you back to your desired commit


git reset HEAD --hard <commit_id>

"Move" your head back to the desired commit.

# This will destroy any local modifications.
# Don't do it if you have uncommitted work you want to keep.
git reset --hard <sha-1>

git checkout

git checkout -b <new branch> <commit_id>
git checkout HEAD~X // x is the number of commits t go back

This will checkout new branch pointing to the desired commit


Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • 1
    thanks for a very detailed and informative answer !! I know this took more effort than the accepted answer but considering the noob i am with git bash i wanted a solution that could use android studios GUI so i accepted the other answer – Shreyans Jan 18 '16 at 10:50
  • Np. Thank you for the appreciation. – CodeWizard Jan 18 '16 at 10:57