90

In IDEA I am trying to push some commits.

I have a requirement that on remote server it looks like single action.

I click to push and see following window enter image description here

I expected to see squash checkbox here but don't see it.

Please help me.

Burhan Ali
  • 2,247
  • 1
  • 23
  • 38
gstackoverflow
  • 31,683
  • 83
  • 267
  • 574
  • 4
    Cannot give IDEA advice, but squashing is part of an interactive rebase or a merge, not a commit. Try looking there. – musiKk Nov 13 '14 at 08:02

3 Answers3

121

You can do it using rebase. Go to VCS/Git/Rebase. Then select Interactive option. It will show you a list of commits, where you can pick which ones you want to squash.

After you hit Start rebasing it will prompt you for a commit message for the squashed commit. After that is done you can push your squashed commit using push dialog.

Squash dialog

More information about rebase in IntelliJ is here.

Bohuslav Burghardt
  • 29,945
  • 7
  • 98
  • 104
  • 10
    it may also be helpful to read this [Git Tools - Rewriting History article](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History) to know what to enter into the "Onto field" of the "Rebase branch" dialogue: e..g `HEAD~3` can be used to select the last 3 commits. – TmTron Sep 25 '16 at 14:26
  • when you squash a bunch of commits together, is the individual details of each of those commits lost? does it just end up looking like one big commit? – ycomp May 26 '17 at 03:36
  • @ycomp Yes, interactive rebase rewrites the history, so the individual squashed commits are lost and a new single one is created in their place. – Bohuslav Burghardt May 26 '17 at 07:25
  • Thanks, can you undo a squash? – ycomp May 26 '17 at 07:27
  • @ycomp I've never actually done that, but it should be possible. Please refer to following SO posts: https://stackoverflow.com/q/10260151/1291150, https://stackoverflow.com/q/134882/1291150 – Bohuslav Burghardt May 26 '17 at 07:49
  • Hmm, there's one dialog before that, this will tell you to use `HEAD~2` notation to work with last two commits. That worked like a charm. https://stackoverflow.com/questions/35018704/intellij-how-to-squash-local-branch-only – jediz Dec 01 '17 at 16:52
  • Thanks, this is the easiest approach still working with Intellij Idea 2019.1 – Chirag Visavadiya Jun 17 '19 at 15:43
40

There is a new way:

Version Control -> Log -> Right click on the commit -> Interactively rebase from here and then you can choose to pick/squash the rest of commits.

ValentinVoilean
  • 1,267
  • 1
  • 13
  • 22
  • 1
    The problem with this approach is that there is no way to select "Squash" for multiple commits and it gets tedious to do it one by one. – Dmitry Serdiuk Dec 11 '18 at 08:35
  • 5
    @DmitrySerdiuk you can shift click to select the commits you want to squash and then right click -> select squash. – Aarjav Apr 12 '19 at 17:07
  • 1
    @Aarjav OH MY GOD this is exactly I thought it is missing! No hints about the right-click menu in the dialog. – o_nix Nov 19 '19 at 12:39
24

For me the simplest way with intellij is :

  • Go to Log tab and chose the commit from which you want to squash
  • Right click and select Reset Branch to this commit
  • Choose the Soft Or Mixin options to keep your changes from the commit
  • Commit your changes and don't forget to check the Amend commit option
Oussama Zoghlami
  • 1,576
  • 16
  • 23