What is the difference between "Revert Commit" and "Undo Commit" in IntelliJ IDEA?

25,827

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).

  1. Open the Version Control window Alt+9 and switch to the Log tab.

  2. Select the last commit in the current branch and choose Undo Commit from the context menu.

  3. 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).

  4. Select the Set active option if you want to make the changelist with the changes you are about to discard the active changelist.

  5. 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.

  1. 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.

  2. 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.

  3. Click Commit to commit a changeset that reverts changes to the selected files in this particular commit.

For more information please refer here

Share:
25,827
Marian Klühspies
Author by

Marian Klühspies

Enthusiastic Software Developer. Started with Android Apps in 2013, moved to backend and frontend development and knows about Spring, Jakarta EE and Node.js. Looking for the easiest, most profitable ad solution for Android, iOS, Unity and so on? Appodeal It combines all major ad networks with just a single registration required and optimizes your profit!

Updated on December 11, 2020

Comments

  • Marian Klühspies
    Marian Klühspies over 3 years

    In IntelliJ Ultimate IDEA 2019.3 (not sure when it was introduced) we have "Revert Commit" and "Undo Commit" options in the Version Control -> Log Tab.

    enter image description here

    What is the difference between those two options?