Smashing Squashing Git Commits for Open Source Contributions
Recently, I made my first contribution to an open source project, homebrew-cask, “a CLI workflow for the administration of Mac applications distributed as binaries”. Basically, it’s a way to install applications through the command line, rather than visiting a website, clicking to save a disk image, opening said disk image, and clicking and dragging the application icon to the application folder. TIme-consuming and full of opportunities for distraction.
…the three great virtues of a programmer: laziness, impatience, and hubris. – Larry Wall
As I was comparing the available applications [or ‘casks’], I noticed that WireOver was missing. Now, it’s not that I use it frequently, but it’s a handy utility that’s just getting started. I checked out the contribution page – bonus: it’s Ruby – and saw how simple it was to add a cask. So, I put one together for WireOver and submitted my pull request. Because I failed to RTFM in full detail, I had a few changes to make for a few lines of code. Which, of course, meant a few commits. The cask audit passed and I thought all was good.
And it sort of was. A request came in this morning to squash my commits. I had previously gone through the link provided in the docs for squashing commits, but ran into roadblocks; specifically, I wasn’t getting my commit messages to show up, only the word “noop” in the text file that pops up.
I found another article, this time geared toward open source contributors, which helped more, but didn’t quite get me there. Here’s what I ended up doing after I had already pushing my feature branch to my fork of the project.
git logto see all of your most recent commits. Make note of how many you want to combine.
qto exit the log.
git rebase -i BRANCH_NAME~NUMBER_OF_COMMITS. As an example, with less yelling:
git rebase -i wireover~5.
git logso I could check the full messages against the hashes in the text editor.
git logagain to make sure all of the commit messages are mashed into one.
git push -f GITHUB_USERNAME BRANCH_NAME. Or, once again with less yelling,
git push -f chrisbodhi wireover.This is dicey because you’re telling git to force the changes. If you don’t though, you’ll get an error message that tells you that your local branch is now somehow behind your remote branch and just go ahead and pull it down and ruin your squashing. But it’s a trap. Don’t do it. If anyone knows of a better way, feel free to hit me up on the bird thing.