Edit 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.
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.
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 commitfixup
discards the new commit message, leaving only the message from the original commit
Make the changes that you want to append to any earlier commit (they will be visible in the Local Changes tab of the Version Control tool window Alt+9 ).
In the Log tab of the Version Control 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.
Modify the commit message if necessary if you've chosen to squash changes.
Click the arrow on the Commit button and choose Commit and Rebase.
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 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
MPS allows you to edit a series of recent commits in the current branch before you apply the changes to a different branch.
Open the Version Control tool window Alt+9 and switch to the Log tab.
-
Select the oldest commit in the series of commits that 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.
If you need to change the order in which the commits should be applied, use the and buttons.
-
Use the Action list to apply the following actions to commits (you can use Ctrl+W/Ctrl+Shift+W to select an action):
pick: applies the selected commit as is.
edit: select to edit the files affected by this commit before applying it. When you select this action, a notification will pop up in the bottom right corner of the IDE window. You can edit the files you want to modify in the editor, and then click Continue in this notification to proceed with the
rebase
operation.drop: ignores the selected commit, so these changes won't be applied.
squash: select to combine the selected commit with the previous one. The commit messages of the two commits will be combined, so this action will be reflected in the branch history. Change the order of commits if necessary so that the commit to which you want to append changes is the previous one in the list.
reword: select this option to edit the commit message before applying it.
fixup: select this option to combine the selected commit with the previous one. The commit message of the fixup commit will be discarded, so this change will be invisible in the branch history. Change the order of commits if necessary so that the commit to which you want to append changes is the previous on in the list.
Edit a branch history and integrate it into another branch
MPS allows you to rebase a branch on top of another branch and edit the source branch history before you apply the changes.
From the main menu select VCS | Git | Rebase.
Select the branch you want to rebase in the Branch field, and the target branch in the Onto field.
In the From field, select the commit starting from which you want to apply the selected branch to the new base.
-
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.
If you need to change the order in which the commits should be applied, use the and buttons.
-
Use the Action list to apply the following actions to commits (you can use Ctrl+W/Ctrl+Shift+W to select an action):
pick: applies the selected commit as is.
edit: select to edit the files affected by this commit before applying it. When you select this action, a notification will pop up in the bottom right corner of the IDE window. You can edit the files you want to modify in the editor, and then click Continue in this notification to proceed with the
rebase
operation.drop: ignores the selected commit, so these changes won't be applied.
squash: select to combine the selected commit with the previous one. The commit messages of the two commits will be combined, so this action will be reflected in the branch history. Change the order of commits if necessary so that the commit to which you want to append changes is the previous one in the list.
reword: select this option to edit the commit message before applying it.
fixup: select this option to combine the selected commit with the previous one. The commit message of the fixup commit will be discarded, so this change will be invisible in the branch history. Change the order of commits if necessary so that the commit to which you want to append changes is the previous on in the list.