DataGrip 2022.2 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. In the Commit tool window Alt+0, select the modified files containing the changes you want to add to the previous commit.

  2. Select the Amend checkbox so that the Commit button changes to Amend Commit and click it.

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. In the Commit tool window Alt+0, select the modified files containing the changes you want to append to an earlier commit.

  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.

Squash commits

If you need to meld any two commits related to the same functionality, you can squash them into one for the sake of cleaner branch history.

  1. In the Log tab of the Git tool window Alt+9 select the commits that you want to combine into one and choose Squash Commits from the context menu.

  2. In the dialog that opens, edit the commit message (by default, it contains the messages from both commits) and click OK.

  3. Push Ctrl+Shift+K the changes to the remote branch.

Drop a commit

You can discard a pushed commit in the current branch without creating an additional commit that reverts the changes.

  • Select a commit you want to discard in the Log view and choose Drop Commit from the context menu.

Edit project history by performing interactive rebase

With Git integration in DataGrip, 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

DataGrip 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 App 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 DataGrip 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 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

DataGrip 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 Git | Rebase:

    Git rebase dialog
  2. Click Modify options and choose --interactive.

  3. From the list, select the target branch onto which you want to rebase the current branch:

    Choose target branch in the Git rebase dialog

  4. If you need to rebase the source branch starting from a particular commit instead of rebasing the entire branch, click Modify options and choose --onto. In the source branch field, enter the hash of the commit starting from which you want to apply the current branch to the new base:

    Specify commit hash with --onto
  5. If the branch you want to rebase is not currently checked out, click Modify options, click Select another branch to rebase, and choose a branch from the list that appears:

    Choose the branch you want to rebase

    DataGrip will check out this branch before starting the rebase operation.

  6. If you want to rebase all commits reachable in the branch, click Modify options and choose --root (for more information on this option, see git-rebase).

  7. If you need to keep empty commits, which are commits that do not change anything from their parent, click Modify options and choose --keep-empty (for more information on this option, see git-rebase).

  8. 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
  9. 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 App 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 DataGrip 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 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
  10. Click Start Rebasing.

Last modified: 26 August 2021