3

I can use 'Revert' in Andriod Studio to give up all changes from my latest commit in Android Studio 3.5.3 as you can see Image 1.

I hope to do the same operation in Vs 2019 to give up all changes by clicking 'Revert' like in Android Studio. There is a Revert command in Visual Studio 2019 too, but I don't know what operation the Revert in Vs 2009 does, you can see what I mean in Image 2.

If I apply some modifications to this project, an error will occur when I launch Revert in Vs 2019 (see Image 3).

If I don't do any changes in this project, a new record named 'Revert Test 3' will be created when I launch Revert in Vs 2019 (see Image 4). I don't know what 'Revert Test 3' means.

Image 1

enter image description here

Image 2 enter image description here

Image 3 enter image description here

Image 4 enter image description here

D Malan
  • 10,272
  • 3
  • 25
  • 50
HelloCW
  • 843
  • 22
  • 125
  • 310

3 Answers3

12

That's just poor terminology.

Android Studio's "revert" does not do a "Git Revert", it does a "Git Reset". This discards your uncommitted changes since the last commit.

Visual Studio actually does a revert, that is, make a new commit in which the changes of the latest commit are turned back.

See also What's the difference between Git Revert, Checkout and Reset?.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
1

"Revert "Test 3"" will create a commit for you reverting all the changes you made in Test 3 commit.

For example, you have a commit where you changed public to private in some method. If you look at the code change of that commit you will se that you changed from public to private. Then when you are doing a revert, the new commit (revert "test 3") will have code changes changing the method from Private to Public instead.

This is specially good if you wanna revert a commit that is not the latest commit.

The reason you are getting an error in image 2 is because you can't revert a commit when you have unstaged changes in the code.

I am not sure about the revert function in Android studio, but if it work as you explain, both the Visual stuido revert and Android studio Revert is the same. Different Extension tools for git will handle operations differently.

Android studio Commit 1 Commit 2

Reverting Commit 2 will make the state of the code as in Commit 1.

Visual studio Commit 1 Commit 2

Reverting Commit 2 will create a new commit "Revert "Commit 2"" but the state of the code in the latest commit will still be as it was in Commit 1.

Fisken
  • 189
  • 5
-1

I encountered the same issue, then i tried to simulate git revert command using couple of other commands

git fetch origin <LastCommitId>

git reset --hard FETCH_HEAD

execute these commands, then your vscode will definitely revert backs the code to the previous version.

Radha Manohar
  • 409
  • 3
  • 15