Intellij git revert a commit

GitIntellij Idea

Git Problem Overview


I was using Eclipse and Egit for a long time and decided to try Intellij.
So far so good, except one thing...
I can't find an easy way to revert an old commit from my repo!!!

In Eclipse the standard process was: Go to Git Workspace -> Click Show History(Right Click Project) -> RIght-Click on the commit I want to revert and press Revert Commit.

In Intellij I can't find anything equivalent. Tried VCS -> Show Changes View but there I can only cherry pick a commit. I also played with the revert option under VCS -> git but got confused by the changelist thing(That may hide the answer, but I don't understand how it works).

I can still revert the commit by issuing git revert <sha> from terminal but that's what I was trying to avoid in the first place by using git from Intellij and not pure terminal.

Is there a way to do easily the revert in Intellij?

Git Solutions


Solution 1 - Git

If you go to Changelist -> Log, and there select the commit, you've got a change detail in the right panel. There you can select all and click a button (or right click -> revert selected changes).

Solution 2 - Git

I know of only one way and it's not as good as doing it command line.

First create a reverse patch. Go into the log, choose any commit and select create patch, check reverse patch and save it anywhere.

Then go into VCS menu and select apply patch and choose the file you just saved.

Commit those changes.

Still, I would go with doing it command line. Gives a proper automatic commit message as well.

Solution 3 - Git

  1. Select the commit you like to revert in the history-log.
  2. From the context-menu select Create Patch...
  3. Select Reverse patch checkbox
  4. Apply the created patch

Solution 4 - Git

I've been looking for that option in Idea 2016.2 and it seems it is no longer there ("revert selected changes"). Instead I was able to do "Reset Current Branch to Here" with "Mized" option, pointing to the latest correct commit. Then I was able to just do the commit again.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondimzakView Question on Stackoverflow
Solution 1 - Gitc0straView Answer on Stackoverflow
Solution 2 - GitAndreas WederbrandView Answer on Stackoverflow
Solution 3 - GitlostinicelandView Answer on Stackoverflow
Solution 4 - GitdomaruView Answer on Stackoverflow