IntelliJ IDEA 2018.1 Help

Keymap:

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.

Modifying the history for a remote branch should be considered carefully and avoided unless really necessary (for example, if you've accidentally pushed some sensitive data). Push of a branch whose history was modified will be rejected as it does not match the remote, so you will have to force push your changes which may lead to data loss.

You cannot modify the history for protected branches where push --force is not allowed (configure protected branches in the Settings/Preferences dialog (Ctrl+Alt+S) under Version Control | Git).

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.

IntelliJ IDEA 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.

Either press Ctrl+K, click on the toolbar, or select Commit from the context menu.

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:

This action can only be applied to commits that have not been pushed yet.

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.

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.