PyCharm 2019.3 Help

Undo changes

Revert uncommitted changes

You can always undo the changes you've made locally before you commit them:

  1. Open the Version Control tool window Alt+9 and switch to the Local Changes tab.

  2. In the active changelist, select one or more files that you want to revert, and select Rollback from the context menu, or press Ctrl+Alt+Z. All changes made to the selected files since the last commit will be discarded, and they will disappear from the Local Changes tab of the Version Control tool window Alt+9.

Undo the last commit

PyCharm allows you to undo the last commit in the current branch (for example, HEAD).

  1. Open the Version Control tool 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 PyCharm 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 tool 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.

Reset a branch to a specific commit

If you notice an error in a set of recent commits and want to redo that part, you can roll back your repository to a specific state. This is done by resetting the current branch HEAD to a specified commit (and optionally resetting the index and working tree if you prefer not to reflect the undo in the history).

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

  2. Select the commit that you want to move HEAD onto and select Reset Current Branch to Here from the context menu.

  3. In the Git Reset dialog that opens, select how you want your working tree and the index to be updated and click Reset:
    • Soft: all changes from commits that were made after the selected commit will be staged (that means they will be moved to the Local Changes tab of the Version Control tool window Alt+9 so that you can review them and commit later if necessary).

    • Mixed: changes made after the selected commit will be preserved but will not be staged for commit.

    • Hard: all changes made after the selected commit will be discarded (both staged and committed).

    • Keep: committed changes made after the selected commit will be discarded, but local changes will be kept intact.

Get a previous revision of a file

If you need to revert a single file instead of discarding a whole commit that includes changes to several files, you can return to a particular version of that file:

  1. Select the required file in any view (in the Project tool window tool window, in the editor, in the Local Changes tab of the Version Control tool window Alt+9, and so on).

  2. Select Git | Show History from the main VCS menu or from the context menu of the selection. The History tab is added to the Version Control tool window showing the history for the selected file and allowing you to review and compare its revisions.

  3. When you've identified the revision you want to roll back to, select it in the list and choose Get from the context menu.

Last modified: 2 April 2020