CLion 2020.1 Help

Edit Git project history

Git allows you to edit your project history. This is useful when you're working on a feature branch and want to clean it up and make it look the way you want before you share it with others. For example, you can edit commit messages, squash together smaller commits related to the same functionality, or split a commit that contains unrelated changes into separate commits, add changes to a previous commit, and so on.

Edit a commit message

If the only thing you need to change is a commit message, you can edit it before you push this commit.

  1. Right-click the commit whose message you want to edit in the Log tab of the Git tool window Alt+9 and select Edit Commit Message from the context menu, or press F2.

  2. In the dialog that opens, enter a new commit message and click OK.

Amend the previous commit

Sometimes you may commit too early and forget to add some files, or notice an error in the last commit that you want to fix without creating a separate commit.

You can do this by using the Amend commit option that appends staged changes to the previous commit. As a result, you end up with a single commit instead of two different ones.

  1. Select the changes that you want to add to the previous commit in the Local Changes view.

  2. Do one of the following before commiting your changes:
    • If you'are using the Commit tool window, click Amend next to the Commit button so that it changes to Amend Commit.

    • If you're using the Commit dialog, click Amend commit in the right pane.

Amend any earlier commit

If you need to add changes to any earlier commit instead of committing them separately, you can do this by using the fixup or the squash action. Both commands append staged changes to the selected commit, but handle commit messages differently:

  • squash adds the new commit message to the original commit

  • fixup discards the new commit message, leaving only the message from the original commit

  1. Select the changes that you want to append to any earlier commit in the Local Changes view.

  2. In the Log tab of the Git tool window Alt+9, right-click the commit that you want to modify with your local changes and select Fixup or Squash Into from the context menu.

  3. Modify the commit message if necessary if you've chosen to squash changes.

  4. Click the arrow on the Commit button and choose Commit and Rebase.

Edit project history by performing interactive rebase

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

Edit the history of the current branch

CLion allows you to edit the commits history in the current branch before you apply the changes to a different branch.

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

  2. Filter the log so that it only displays commits from the current branch:

    Filter log by branch
  3. Select the oldest commit in the series of commits that you want to edit, right-click it and choose 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:

    Interactive Rebase dialog

    If the Interactively Rebase from Here option is disabled, this may be due to one of the following reasons:

    • the selected commit has several parents

    • the selected commit is not in the current branch

    • the selected commit is pushed to a protected branch

    To identify the reason, hover the action in the context menu and look for the message in the status bar:

    Status bar message
  4. You can perform the following changes to the branch history:

    • Change the order in which commits should be applied: use the up arrow and down arrow buttons to move commits up and down the list.

    • Pick a commit: this is the default state for all commits. If you need to undo an action you've already taken on a commit, click Pick icons actions rollback so that this commit is applied as is.

    • Edit: click Stop to Edit the Pause button so that when you start the rebase, you stop at this commit to be able to edit it.

      When rebase is stopped at a commit, a notification pops up in the bottom-right corner of the CLion window letting you continue or abort the rebase:

      the rebase status notification
      You can modify this commit using the context actions (such as Revert, Undo, Amend, and so on before continuing the rebase. If you don't perform any actions, this commit will be applied as is.

      If you've closed the notification, from the main menu choose VCS | Git | Continue rebase to resume it.

    • Reword the commit message: click Reword or double-click a commit and edit the text in the mini-editor that opens.

    • Combine two commits into one: select the commit you want to meld into the previous one and click Squash or the arrow next to the Squash button and then Fixup.

      If you click Squash, by default the messages from the two commits will be combined, so if you don't modify the resulting commit message this action will be reflected in the branch history.

      If you click Fixup, the commit message of the fixup commit will be discarded, so this change will be invisible in the branch history.

      In both cases, you will be able to edit the commit message in the mini editor that opens when you apply one of these actions.

    • Ignore a commit: click Drop so that the changes from the selected commit are not applied.

    • Undo all changes: click Reset to discard all actions you've applied to the commits.

    As a result, the Rebasing Commits dialog shows a graph illustrating all actions you've applied to commits in your branch, so that you can review them before starting the rebase:

    Interactive Rebase graph
  5. Click Start Rebasing.

Edit a branch history and integrate it into another branch

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

    Interactive Rebase dialog
  5. You can perform the following changes to the branch history:

    • Change the order in which commits should be applied: use the up arrow and down arrow buttons to move commits up and down the list.

    • Pick a commit: this is the default state for all commits. If you need to undo an action you've already taken on a commit, click Pick icons actions rollback so that this commit is applied as is.

    • Edit: click Stop to Edit the Pause button so that when you start the rebase, you stop at this commit to be able to edit it.

      When rebase is stopped at a commit, a notification pops up in the bottom-right corner of the CLion window letting you continue or abort the rebase:

      the rebase status notification
      You can modify this commit using the context actions (such as Revert, Undo, Amend, and so on before continuing the rebase. If you don't perform any actions, this commit will be applied as is.

      If you've closed the notification, from the main menu choose VCS | Git | Continue rebase to resume it.

    • Reword the commit message: click Reword or double-click a commit and edit the text in the mini-editor that opens.

    • Combine two commits into one: select the commit you want to meld into the previous one and click Squash or the arrow next to the Squash button and then Fixup.

      If you click Squash, by default the messages from the two commits will be combined, so if you don't modify the resulting commit message this action will be reflected in the branch history.

      If you click Fixup, the commit message of the fixup commit will be discarded, so this change will be invisible in the branch history.

      In both cases, you will be able to edit the commit message in the mini editor that opens when you apply one of these actions.

    • Ignore a commit: click Drop so that the changes from the selected commit are not applied.

    • Undo all changes: click Reset to discard all actions you've applied to the commits.

    As a result, the Rebasing Commits dialog shows a graph illustrating all actions you've applied to commits in your branch, so that you can review them before starting the rebase:

    Interactive Rebase graph
  6. Click Start Rebasing.

Last modified: 11 June 2020