Undo the last commit
IntelliJ IDEA allows you to undo the last commit in the current branch (for example, HEAD).
Note: You cannot undo a commit if it was pushed to a protected branch, that is a branch to which force –push is not allowed (configure protected branches in the Settings/Preferences dialog Ctrl+Alt+S under Version Control | Git).
-
Open the Version Control window Alt+9 and switch to the Log tab.
-
Select the last commit in the current branch and choose Undo Commit from the context menu.
-
In the dialog that opens, select a changelist where the changes you are going to discard will be moved. You can either select an existing changelist from the Name list, or specify the name of a new changelist (the commit message is used by default).
-
Select the Set active option if you want to make the changelist with the changes you are about to discard the active changelist.
-
Select the Track context option if you want IntelliJ IDEA to remember your context and reload currently opened files in the editor when this changelist becomes active.
Revert a pushed commit
If you notice an error in a specific commit that has already been pushed, you can revert that commit. This operation results in a new commit that reverses the effect of the commit you want to undo. Thus, project history is preserved, as the original commit remains intact.
-
Locate the commit you want to revert in the Log tab of the Version Control window Alt+9, right-click it and select Revert Commit from the context menu. This option is also available from the context menu of a commit in the File History view. The Commit Changes dialog will open with an automatically generated commit message.
-
If the selected commit contains several files, and you only need to revert some of them, deselect the files you do not want to touch.
-
Click Commit to commit a changeset that reverts changes to the selected files in this particular commit.
For more information please refer here