Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset to my last commit in Android Studio

I commit changes to git from Android Studio, after that I have made some changes in my project that gives me errors, and now I want to get back that commited version that has no errors. How can I do that?

like image 292
KiZo Avatar asked Apr 13 '15 22:04

KiZo


People also ask

How do I reset my last commit?

In order to undo the last commit and discard all changes in the working directory and index, execute the “git reset” command with the “–hard” option and specify the commit before HEAD (“HEAD~1”).

How reset last commit in remote?

To undo the last commit from a remote git repository, you can use the git reset command. command. This will undo the last commit locally. command to force push the local commit which was reverted to the remote git repository.


2 Answers

To undo your latest changes and reset to the most recent commit:

Go to VCS -> Git -> Reset HEAD..

Change Reset type to hard to remove those changes.

It will look like this. You can validate the reset before you do it if you want.

enter image description here


What happens if you click Validate?
A screen will pop up that shows the changes that were made in the commit you are about to reset to. You can view diffs per file that show what the commit changed in that file. It's more or less equal to what $ git show in a terminal would do.

Contrary to what I assumed before, it does not show what files will be affected when you perform the reset.

like image 171
Tim Avatar answered Oct 07 '22 21:10

Tim


Just get your commit id using git log. Then you can use (with 0d1d7fc32 for example):

# This will detach your HEAD, that is, leave you with no branch checked out: git checkout 0d1d7fc32 

or if you don't want to save your changes (hard reset):

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

If you want to go back to the last commit (without saving changes), then no need to get the id, go for:

git reset --hard HEAD 

From this post

like image 41
DavidL Avatar answered Oct 07 '22 20:10

DavidL