IntelliJ - How to squash local branch only
Asked Answered
B

2

20

When using Git inside of IntelliJ, how do I squash all of my commits for a local branch? What settings do I use in the rebase branch window?

I've tried setting the Onto to local/master and From to my branch, but then it goes and tries to merge master changes into my branch for each commit I did, even though I typically rebase my branch onto master every morning...so there SHOULD be no conflicts. Yet it almost always finds conflicts and causes merge issues. I ONLY want to squash the branch commits and messages so when I push to GitHub it only sees one.

enter image description here

Buroker answered 26/1, 2016 at 16:24 Comment(1)
@Buroker I found this answer very helpful to squash locally before push Combine commits to single pushGauhati
M
33

It might be a little uncomfortable but you can use the git notation of HEAD~ so in the "Onto" field you'd write the amount of commits you want to include like:

In this example I have 4 (the last 4) commits I want to combine into 1.

rebase interactive dialogue

In the opening dialog the entries are listed in order, so you need to squash all after the first one with the drop box. (I made the first a reword but that's not needed as there will be a message-change dialog for the squashing anyway, so it can be left on 'pick')

squashing

then just a new message for the combined commits and you're done.

commit message

Murvyn answered 10/5, 2017 at 9:41 Comment(0)
G
2

If you want something like "git merge -squash", which means to merge a branch to another branch (possibly "master") with one commit containing all of the changes, you can use "Merge Changes..." option in IntelliJ. Just double press shift and type "Merge Changes". In the opened dialog, select which branch you want to merge and then select "Squash commit" option.

enter image description here

Goby answered 26/5, 2020 at 7:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.