Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly squash commits using SourceTree?

We're using Git as our source control system, and I like to commit my code on a regular basis. This does mean that when I'm ready to push to the shared repo I've created quite a few nonsense commits that I'd like to squash away before pushing.

Using SourceTree that should be a simple thing, but I keep running into issues where not all selected commits are being squashed together. Let me show some images of what I do using a sample repo with some checkins:

Initial situation

I click the first checking and choose to 'rebase children interactively'

Context menu

A pop will appear with all the checkins:

Popup

On this popup I click the 'fifth' checkin and hit the squash with previous 3 times until the screen looks like this:

Squashed in popup

All's fine you'd think, but then when hitting the 'ok' button, this is what I end up with:

End result

Why oh why does it not include the 'Second' commit in the end result? Judging by the looks of the popup you'd think this is included as well. I can do the same thing again to get the second in there, but I just can't fathom why it works this way or how to squash them all in one go.

Any help would be appreciated.

like image 770
Robba Avatar asked Feb 14 '17 08:02

Robba


People also ask

Is it good practice to squash commits?

As a general rule, when merging a pull request from a feature branch with a messy commit history, you should squash your commits. There are exceptions, but in most cases, squashing results in a cleaner Git history that's easier for the team to read.

How do you squash commits in a pull request?

When you select the Squash and merge option on a pull request on GitHub.com, the pull request's commits are squashed into a single commit. Instead of seeing all of a contributor's individual commits from a topic branch, the commits are combined into one commit and merged into the default branch.


1 Answers

It was a bug in SourceTree, see this bug report. According to the bug history, it was closed as fixed in May 2021.

like image 92
knittl Avatar answered Oct 19 '22 01:10

knittl