As the Sample Programs repo rapidly approaches 5000 commits, I figured it was time to clean up our git history with a new trick: commit squashing. In this article, we’ll talk about what that means and why I decided to make the change.
Table of Contents
What Is Commit Squashing?
Yeah, this is a fair question! Squashing commits is something that has been around for awhile and is even fully integrated into the GitHub workflow, but I had never used it until recently. After all, my typical feature branch merge seemed to be working just fine.
However, I tend to get bored of repetitive processes, so I figured I’d try to spice it up. Surely, there are other ways to manage a git repository, right? Well, there is, and it’s called squashing!
Commit squashing is a simple idea. Instead of taking a branch and merging it into another branch with a merge commit, we convert our list of commits into a single commit first. Then, when it’s merged, there’s only one new commit for that entire feature on the main branch.
In my typical workflow, I would merge a branch which creates a messy history where all the commits from both branches are interspersed. Alternatively, squashing commits creates a linear history where each commit represents a new feature. This is perfect for a repository like Sample Programs which is driven by small updates and changes.
How Has Commit Squashing Helped Sample Programs?
On it’s own, commit squashing isn’t really that big of a deal. Sure, it’s nice because it keeps the commit history clean:
Clearly, that’s much nicer than how it used to be:
That said, if you don’t spend a lot of time looking at the history, who cares? Well allow me to introduce you to the project homepage:
Notice how all the files and folders have commit messages from when they were last updated? Well, the default behavior of squashing commits in GitHub is a commit message that includes a link to the related pull request. In other words, just by peeking at the project page, we can jump right to the pull request that generated a certain file.
I particularly like this for the Sample Programs repo because we can see exactly what was most recently added:
Notice how pull requests that were not merged result in really lame commit messages. For example, the last commit for the `/g/` archive just says “change validating if input < 2”. We have no clue what language or script that applies to, so it’s basically noise.
On the flip side, anything that has a link to a pull request has a relatively consistent naming scheme. That’s because we enforce pull request naming conventions that pay off here.
Now, we haven’t been squashing commits for very long, and not everyone on the team agrees with the idea. That said, I’m really excited to be able to look over a list of scripts and be able to jump write to their pull request. For example, imagine how nice the list of Python scripts will look with proper links:
Overall, I’m really excited about this change! Let’s see how things shape up in the next few months.
What’s Ahead for the Sample Programs Repo?
This was a quick update because I just wanted to share my excitement around a new thing we’re trying on the repo. At the moment, we’re in the middle of Hacktoberfest, so there’s a lot of work that still needs to be done. As I’ve said before, our biggest goal this year is to reduce tech debt.
Going forward, I’m hoping to focus more on the article side of things. After all, as much as I love having a collection of code snippets, I think the educational piece is the most important. Of course, that’s going to require authors, and I’m not sure we’ll ever get the same sort of enthusiasm for documentation. That said, I’m hopeful!
With that said, hopefully you’ll consider making a pull request to the repo to help us out. We’re always looking for new people to share their knowledge. There’s basically an endless stream of work, so don’t worry about having nothing to contribute.
Also, if you’d like to help The Renegade Coder, you can do that by checking out this list. There, you’ll find everything you need to help the community grow like our Discord, YouTube channel, and Newsletter.
Likewise, here are some related Sample Programs articles, if you’re interested:
- The Sample Programs Repos Are Ready for Hacktoberfest 2020
- Sample Programs 100 Article Release
- Sample Programs Repo Now Supports Testing
Otherwise, take care! Thanks for stopping to check out the site.
Poetry was life changing for me as a Python developer. You really ought to try it.
Making a Sandwich is Not Rocket Science: How Elitists Always Stay on Top
If you're struggling in the tech field, please read this. I'm looking to build a community for folks who lack proper mentors.