100

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,258
  • 1
  • 28
  • 38
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
  • 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

4 Answers4

125

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
  • 33,626
  • 7
  • 114
  • 109
  • 11
    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
  • 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
  • Dont forget to "force push" – Stefan Nov 11 '21 at 11:33
43

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,365
  • 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
  • 6
    @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
24

For me, the simplest way with IntelliJ is:

  • Go to Log tab and choose 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
Pang
  • 9,564
  • 146
  • 81
  • 122
Oussama Zoghlami
  • 1,660
  • 17
  • 24
4

With the latest version of IntelliJ you can simply select all the commits, right-click -> Squash commits

M.Paniccia
  • 157
  • 2
  • 7
  • What are the potential dangers of doing this? This seems deceivingly easy. What does IntelliJ do under the hood? – payne Mar 23 '22 at 03:53