PyCharm 2017.3 Help

Edit project history

Git allows you to edit your project history if at some point you need to rewrite your commits as if you made them in a different way.

Combine staged changes with the previous commit (amend commit)

Sometimes you may find yourself in a situation when you commit too early and forget to add some files or notice an error in the last commit that you want to fix without it being reflected in the project history.

PyCharm allows you to do this by using the Amend commit option that combines the previous commit with the current changes, and you end up with a single commit instead of two different commits.

To amend the previous commit, do the following:

  1. Invoke the Commit changes dialog and select the changes that you want to use to fix up the previous commit.
  2. Either press Ctrl+K, click icon commit on the toolbar, or select Commit from the context menu.
  3. In the Commit Changes dialog that opens, select the Amend commit option on the right before committing your changes.

Edit a commit message

If the only thing you need to change is a commit message, you can edit it without making any other changes:

  1. Locate the commit whose message you want to edit in the Log view, right-click it and select Reword from the context menu, or press F2.
  2. In the dialog that opens, enter a new commit message and click OK.

Edit project history by performing interactive rebase

Git allows you to edit project history for the sake of making it linear and meaningful by performing interactive rebase. This allows you to clean up a messy commits history by altering individual commits, changing their order, squashing commits into one, skipping commits that contain extraneous changes, etc. before you integrate changes from your feature branch to another branch.

Edit the history of the current branch

PyCharm allows you to edit a series of recent commits in the current branch before you apply the changes to a different branch.

  1. In the Log tab of the Version Control tool window select the oldest commit in the series of commits you want to edit, right-click it and select Interactively Rebase from Here.

    The Interactive Rebase dialog will be displayed containing the list of all commits in the current branch that were made after the selected commit.

  2. Use the Action drop-down list to apply the following actions to commits:

    • Pick: applies the selected commit as is.
    • Edit: select this option to edit the files affected by this commit or the commit message before applying this commit.
    • Skip: ignores the selected commit.
    • Squash: select this option to combine the selected commit with the previous one.
    • Reword: select this option to edit the commit message before applying this commit.
    • Fixup: select this option to combine the selected commit with the previous one and use the message from the previous commit with the "fixup!" prefix.
  3. Use the Move Up and Move Down buttons to modfiy the order in which commits should be applied.

Edit a branch history and integrate it into another branch

PyCharm allows you to rebase a branch on top of another branch and edit the source branch history before you apply the changes.

  1. From the main menu select VCS | Git | Rebase.
  2. Select the branch you want to rebase in the Branch field, and the target branch in the Onto field.
  3. In the From field, select the commit starting from which you want to apply the selected branch to the new base.
  4. Make sure the Interactive option is selected, and click Rebase.

    The Interactive Rebase dialog will be displayed containing the list of all commits in the current branch that were made after the selected commit.

  5. Use the Action drop-down list to apply the following actions to commits:

    • Pick: applies the selected commit as is.
    • Edit: select this option to edit the files affected by this commit or the commit message before applying this commit.
    • Skip: ignores the selected commit.
    • Squash: select this option to combine the selected commit with the previous one.
    • Reword: select this option to edit the commit message before applying this commit.
    • Fixup: select this option to combine the selected commit with the previous one and use the message from the previous commit with the "fixup!" prefix.
  6. Use the Move Up and Move Down buttons to modfiy the order in which commits should be applied.
Last modified: 29 November 2017