12

I would like to look at an old commit of my app in Android Studio in order to compile and run it. I don’t want to reset back to the previous commit or change my commit history or anything like that. When I’m done, I want to go back to the latest version.

On the command line, this would be a simple

git checkout <hash>

So how can I do this in Android Studio?

I haven’t tried to do it on the command line, because I’m afraid Android Studio might get heartburn when I modify its files externally. Reassurance that I can work with git outside of Android Studio without problem would be fine too.

2 Answers 2

46

If you want to checkout commit using Android Studio (or other IntelliJ IDEA based IDE) just go toVersion Control view (alt+9) and click the Log tab. Type your commit hash in Filter input, right-click on the commit entry and click the Checkout Revision option.

What's more, if you want to work with a command line, simply use git from command line. I'm working with Git using only command line and nothing wrong happend yet. The only thing that you have to remember is to wait for reindexing end.

4
  • 1
    This was exactly what I needed! Thank you very much. The version control in Android Studio is so powerful. I love it.
    – Jeff.H
    May 4, 2017 at 16:37
  • I'm not seeing how to do the above within Android Studio 4.x. Perhaps this answer needs to be refreshed for a current version.
    – Lance Kind
    Aug 13, 2021 at 20:30
  • @LanceKind I have Android Studio Arctic Fox 2020.3.1 (4.3 in old number system) and that option is still available.
    – Kamil
    Aug 16, 2021 at 6:13
  • 2
    I'm on MacOS and also on Arctic Fox. Alt+9 isn't getting me there so I'm guessing how your getting into the dialogue window. Specifically, I can't find the "log" tab. I can click on the "commit" widget on the left hand of the IDE screen, but no log tab there. View menu bar item doesn't show anything related. So at the Git menu bar item ... Ah "show Git log" is a menu bar item and that shows me the checked in versions.
    – Lance Kind
    Aug 19, 2021 at 21:05
1

A git repository contains the all history at all time. So when you are cloning a repository, you are cloning it with its full history, and then, you can make a branch from whatever commit you want:

$ git checkout -b aNewBranch SHA1

with SHA1 representing the commit id from which you want to proceed.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.