How to combine group of local commits to single push in IDEA?
Asked Answered
C

4

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.

Clothesline answered 12/11, 2014 at 23:17 Comment(1)
Cannot give IDEA advice, but squashing is part of an interactive rebase or a merge, not a commit. Try looking there.Hippy
D
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.

Dippold answered 13/11, 2014 at 8:5 Comment(4)
it may also be helpful to read this Git Tools - Rewriting History article 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.Escapade
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. #35019204Trimorphism
Thanks, this is the easiest approach still working with Intellij Idea 2019.1Ametropia
Dont forget to "force push"Jaquelinejaquelyn
A
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.

Avaricious answered 10/10, 2018 at 7:28 Comment(2)
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.Linctus
@DmitrySerdiuk you can shift click to select the commits you want to squash and then right click -> select squash.Typebar
P
25

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
Polyhistor answered 13/3, 2018 at 23:28 Comment(3)
This is indeed the simplest way and I find it to be the least stressful and error prone.Opprobrium
I suggest that on step 3 it would be better to choose a Soft option instead of Mixed to have all changes already staged for commit.Barnie
The only first step was enough for me.Donnetta
W
5

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

Wiersma answered 8/10, 2021 at 9:38 Comment(1)
What are the potential dangers of doing this? This seems deceivingly easy. What does IntelliJ do under the hood?Blackness

© 2022 - 2024 — McMap. All rights reserved.