How to revert project back to a previous commit in android studio - android

I am working on a project in android studio and would like to revert to a previous push. I attempted
VCS => Git => Reset Head (Hard)
but my project in Android Studio is unchanged, likely because I'm doing something wrong. I would like to revert the project in Android Studio to a specific earlier commit that I've pushed and I see on github. I do not care about any changes that I have made since the earlier push.
Additionally, I would like this to be done through the GUI within Android Studio if possible.

Android Studio Instructions: if you want to do this in Android Studio, press alt + 9 (or Command + 9 on Mac) to open the Version Control panel. Switch to the Log tab and right click on a previous commit. Select Checkout Revision.
Command line instructions: Open the command line tool you are using.
Go to the Android app's Git directory (using cd).
Execute git log and find the previous commit you want to revert to.
commit 7c247be6d8975dc88f6cc2631c154786a1f3b79e
Author: John Doe <john#doe.ca>
Date: Fri Jun 11 22:37:35 2015 -0400
Some helpful commit message should be here.
If that is the commit you want to revert to, then execute git checkout 7c247b.

Open the Version Control Panel using alt + 9 and click on Log. This should show a list of commits. Right click on the commit you want to revert to and select Reset Current Branch to Here. This should bring up a list of options to keep or discard changes when reverting. Select Hard to discard any current changes and click Reset.

The icon surrounded by red rectangle in image will do the trick

In android studio 4.0, go to version control -> Log.
Then select the commit you want to revert to.
Choose Reset current branch to here.
You ll see a popup, select Hard and its done.

Android Studio -> Version Control -> Select your commit -> Right panel -> Select you want to be reverted file.
Then you can get the new reverted change, commit -> done.

Android Studio > check bottom toolbar -> click on git -> select log tab -> right on particular commit -> reset current branch to here -> select hard reset
Also if u have already pushed code to server
u need to run
git push -f origin branch_name

MacOS users
Rollback Changes
⌘ Command + ⌥ Option + Z
VCS -> Git -> Rollback...
//or
VCS Local Changes Toolbar -> Rollback...
//or
Commit Changes -> Rollback...

While push is selected branch to undo;
example brach name -> push_will_be_undone
git push -f origin push_will_be_undone
Writing did my job and it worked for me

Right click on folder where you Github folder, press Git Bash Here and type git reset --hard

Related

Android Studio Git works weird I think?

Hello I am using Android Studio 2020.3.1 Patch 4. I'm using Git and committing a state. And then add some code and I want to return to where I was (before I entered the new code). When I checkout it does nothing. Even if I restarted Android Studio. And when I Reset Current Branch to Here.. initially it does nothing but if I restart the Android Studio new code is gone(as I wanted). What am I doing wrong?
The correct command to remove the newly added but not commited code is:
git stash
It will remove the unstaged codes and return the code-base to the last commit.
We normally use 'git checkout' to move around between different commits.
If you want to do this process without command, you will need to "Rollback changes". The keyboard shortcut for macos for this is: option + command + z.

How to discard local changes in Android Studio GUI?

I want to discard the local changes I made in an Android Studio project.
I tried to perform a pull, the GUI gives me 5 options, which option should I choose?
Octopus
Ours
Subtree
Recursive
Resolve
In Android Studio do the following:
-Open the Version Control tool window Alt+9 and switch to the Log tab.
-Select the recent commit and right click on it than select Reset Current Branch to Here.
-A Git Reset popup will open -> select Hard -> click Reset
You originally asked which strategy argument to use with git pull to discard your own work (there is a pending edit that will change the question, if the edit is approved). The answer is: None.
Don't use git pull at all. Run git fetch first:
git fetch origin
This brings over all the new stuff from the other Git you have your Git calling "origin".
Now that you have everything they have, simply stop using what you have been using, and switch to theirs:
git reset --hard origin/master # assuming you're on your "master"
You may also want to use git clean -fdx to remove build artifacts, but that's a separate issue.
In Android studio do the following:
Go to VCS -> Git -> Reset HEAD
Change Reset type to hard

How to reset to any of the previous commit in android studio?

I made some commits to git from android studio. Now I want to reset to one of the committed version. How can I do that within android studio?
At last I have found the solution.
Go to VCS -> Git -> Show History
From Log, right click on the required committed version and select Reset Current Branch to Here.
Select Hard and click on Reset button.
open terminal in android studio :
You can do this by following two commands:
git reset --hard [previous Commit SHA id here]
git push origin [branch Name] -f
It will remove your previous git commit.
If you want to keep your changes you can also use:
git reset --soft [previous Commit SHA id here]
Then it will save your changes.
For more details How do you undo the last commit?

Switching branch does not update android studio

I have a stable branch that I am doing some work on. Then to do some experimental stuff, I create another branch called experi and then started doing some work there. Then I switch back to my stable branch. However, android studio is still showing the code for the experi branch. How do I make it so that when I switch from one branch to another, android studio switches content?
I created the branch using
git checkout -b experi stable
and then to switch I do
git checkout experi
basically how do I keep the branches independent?
At least I want to be able to go back to my stable branch (before the news stuff intended for experi)
This is so weird. Everything I did was correct. But in order for the IDE to refresh I have to click on the bottom tab labeled "Version Control". It is next to the "Android Monitor" tab.
Android Studio doesn't sync with your git repo. Make sure you are on the desired branch. Note: SourceTree , AS can indicate you are on a different branch . But the command line never lies.
Synchronize your gradle and clean the project.
In Android Studio : View > Tools Windows > Gradle

Android Studio: Unregistered VCS root detected

Unregistered VCS root detected
The directory /Users/*****/AndroidStudioProjects/Signin/google-services is under Git, but is not registered in the Settings.
Add root Configure Ignore
How to resolve this?
Please help.
Press "add root" when the warning message appears.
This will make idea register the "unregistered vcs root", and you can use the git features of IDEA/Android studio. Nothing bad will happen if you do not press "add root", but I suspect you will get the same warning on each startup of android studio/IDEA.
You are able to ignore that warning if you are not interested in using Android Studio's git integration. Or, you can enable git integration under the VCS | Enable Version Control Integration menu.
VCS stands for "Version Control System", aka "undo on steroids". No programmer should be without it.
IDEA (which Android Studio is based on) sees some signs in your project directory that your project source is set up to use a Version Control System.
In this case, the VCS in use is git. The sign is the presence of a projectdir/.git subdirectory.
That indicates that you either created this project directory by "cloning" this project from a git repo:
$ git clone https://github.com/projectname/reponame.git
Or that you created your own git repo in the project directory, by cd'ing to the projectdir and running the command:
/path/to/projectdir $ git init-db
By clicking "add root" you tell IDEA to add this git repo to IDEA's internal settings for the project, so you can use the IDEA features that support using git. I recommend using it, it won't interfere with your ability to use git from the command line, but some of the IDEA git features are handy.
If you don't know/use git, I highly, highly recommend that you learn it. It will make your life a lot easier, in the long run. As I said, it's like "undo" on steroids.
If you already know how to use git, here are a few of IDEA's git features.
The niftiest feature is that you can select a few lines of code, right-click and select Git/Show History for Selection.
The most useful feature (to me) is Alt-9 aka View/Tool Windows/Version Control.
This brings up the version control window, a pane across the bottom of the
IDEA gui.
By default the Version Control Window just shows "Default" (in bold)
and "Unversioned Files".
Expand "Default" to see the files that changed.
Expand "Unversioned Files" to see any files that need to be added to git.
The color indicates the status, all configurable of course, the default config is that blue indicates changed, green indicates added, etc.
Right-click/Show Diff on a changed file and it gives you a nice visual
diff, sort of reminiscent of Meld's UI, which is one of my favorite,
because it uses these sort of cartoon "word ballon" indicators for
each difference, to illustrate where the difference would be in the
other version.
Also, the side of the visual diff that shows the current file appears
to be a fully functional (or mostly functional) IDEA editing window,
making it easy to fix any gratuitous differences.
Some useful related links:
https://www.jetbrains.com/help/idea/2016.1/file-status-highlights.html?origin=old_help
Also, at the same site see:
Howto/General Guidelines/Version Control with Intellij IDEA/VCS-Specific Procedures/Using Git Integration/Checking Git Project Status
Reference/Version Control Reference/File Status Highlights
I'd include links directly to these but apparently stackoverflow doesn't trust me yet.
You can disable Android Studio git integration and get rid of the annoying warning. Here's how with Android Studio 2.1.1 for the Mac OS X:
Menu -> "Android Studio/Preferences...".
In Preferences window: Click on to open "Plugins"
In the Plugins frame: uncheck "Git
Integration".
Disabling "Git Integration" also disables GitHub, Google Cloud Testing, Google Cloud Tools Core, Google Cloud Tools For Android Studio plugins. (good riddance). By default, Android Studio enables all plugins at install time even though most devs will use only 10% of them.
FIRST STEP: Click in configure link.
SECOND STEP: then select the correct and add
If you see this message whenever you open Android Studio and create a new project, It's because your projects home directory is set as a VCS root. Maybe It was a mistake, set by you unintentionally. That was my case.
To solve it.
Just delete .git directory from projects home directory.
Delete: ../AndroidStudioProjects/.git

Categories

Resources