IDEA git commit push revert

  

  1. Revert uncommitted changes

    You can always undo the changes you've done locally before you have committed 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 Revert from the context menu, or press Ctrl+Alt+Z. All changes done to the selected files since the last commit will be undone, and they will disappear from the Local Changes view.

    Undo the last commit

    IntelliJ IDEA allows you to undo the last commit in the current branch (i.e. HEAD):

    You cannot undo a commit if it was pushed to a protected branch, i.e. a branch to which push --force is not allowed. You can configure the list of protected branches in the Settings dialog (Ctrl+Alt+S) under Version Control | Git.

    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 Namedrop-down 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 view, right-click it and select Revert from the context menu. 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

      信息来自:https://www.jetbrains.com/help/idea/using-git-integration.html#revert-local-changes
原文地址:https://www.cnblogs.com/mengjianzhou/p/7662313.html