Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 386
Marian Klühspies Avatar asked Dec 10 '19 12:12

Marian Klühspies


People also ask

What is Revert commit in IntelliJ?

Revert selected changesIntelliJ IDEA lets you undo selected changes from a pushed commit if this commit contains multiple files and you only need to revert some of them. In the Log view select the commit containing the changes you want to discard.

What does it mean to revert a commit?

Summary. The git revert command is a forward-moving undo operation that offers a safe method of undoing changes. Instead of deleting or orphaning commits in the commit history, a revert will create a new commit that inverses the changes specified. Git revert is a safer alternative to git reset in regards to losing work ...

What happens after revert commit?

If a past commit added a new line of code to a Java file, a git revert on that commit will remove the added line. When you revert a Git commit, the changes from the targeted commit are removed from your local workspace. A new commit is also created to reflect the new state of your repository.

What will undo commit do?

Definition of Git Undo Last Commit Git undo last commit is used to scrap the most recent record of changes made to a file in a distributed version control system (DVCS) without losing the changes themselves. The changes can be retained so the user can edit them and re-commit them.


1 Answers

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

like image 195
Malik Motani Avatar answered Sep 25 '22 01:09

Malik Motani