0

I use Github in my project in Android Studio 3.3.

I find the Revert command display in three position, please see Image 1, Image 2, Image 3-1, and Image 3-2 ( Image 3-2 is a detail window of Image 3-1, and Revert command is in left-middle of Image 3-2).

What are different about the three Revert commands?

Image 1 enter image description here

Image 2 enter image description here

Image 3-1 enter image description here

Image 3-2 enter image description here

HelloCW
  • 843
  • 22
  • 125
  • 310

2 Answers2

2

TLDR:

Image 1, Version Control -> Log -> Revert, edits the repository that makes it looks like the time before that commit was made, and optionally makes a commit.
Image 2, VCS -> Git -> Revert..., drops uncommitted changes for selected files.
Image 3, Local History -> Show History, acts like 1, but inside a tool that is JetBrains specific, nothing related to Git.


Details:

  1. Version Control -> Log -> Revert actually does this below: A revert, then add and commit

    • (The reset at :29 is just want to restore the Git repository for testing.)
    • First, it do a git revert, making some edit outside the control of Git, and the repository become dirty (needs to commit).
    • Then, pop up a commit window, asking for you to commit.
    • Second, after you decided what file to commit, make a git add and git commit.
    • Conclusion: Version Control -> Log -> Revert = git revert (+ git add + git commit, optional ) = Edit the repository like before the commit it is reverted to.
  2. VCS -> Git -> Revert... only activates when the repository is dirty. It actually does this below: A rm, then checkout

    • First, it do a git rm --cached -f
    • Then, it do a git checkout HEAD
    • Conclusion: VCS -> Git -> Revert... = git rm + git checkout = Drop any uncommitted changes.
  3. Local History -> Show History is a standalone built-in VCS managed by IntelliJ IDEA (and other JetBrains IDE, including Android Studio which is patched from IntelliJ IDEA community), it has no relationship with that Git, or other kind of VCS, and will be cleared if you do a File -> Invalidate Caches / Restart -> Invalidate. That Revert acts like Version Control -> Log -> Revert, both restore the source to the history.

Geno Chen
  • 4,916
  • 6
  • 21
  • 39
1

VCS -> Git -> Revert... will not revert a commit, only revert your local staged changes.
It is the equivalent of git reset HEAD, to unstage changes added to the index.

The revert shown in the Log will actually git revert a commit, that is: make a new commit which will cancel the changes introduced by the reverted commit.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250