How to Flatten git Commits
One of my least favorite tasks as a software engineer is resolving merge conflicts. A simple rebase is a frequent occurrence but the rare massive conflict is inevitable when many engineers work in a single codebase. One thing that helps me deal with large rebases with many merge conflicts is flattening a branch's commits before fixing merge conflicts. Let's have a look at how to flatten those commits before resolving those conflicts!
My typical command for rebasing off of the main branch is:
# While on the feature branch...
git rebase -i master
To flatten commits before the rebase, which can make resolving merge conflicts easier, you can slightly modify the original command:
# While on the feature branch...
# git rebase -i HEAD~[NUMBER_OF_COMMITS]
git rebase -i HEAD~10
The example above would flatten the last 10 commits on the branch. With just one single commit, you avoid the stop-start nature of fixing merge conflicts with multiple commits!
This is the hardest thing I've ever had to write, much less admit to myself. I've written resignation letters from jobs I've loved, I've ended relationships, I've failed at a host of tasks, and let myself down in my life. All of those feelings were very...
Back in late 2012 it was not easy to find open source projects using requestAnimationFrame()
- this is the hook that allows Javascript code to synchronize with a web browser's native paint loop. Animations using this method can run at 60 fps and deliver fantastic...
One device and app feature I've come to appreciate is the ability to change between light and dark modes. If you've ever done late night coding or reading, you know how amazing a dark theme can be for preventing eye strain and the headaches that result.
I wrote a post titled Get Slick with MooTools Kwicks ages ago. The post was quite popular and the effect has been used often. Looking back now, the original code doesn't look as clean as it could. I've revised the original...
Some of the code in my previous comment got stripped out. The command I use to merge a branch into master while flattening it to a single commit is:
Seems there are always multiple ways to do things, especially in Git.
Also it’s possible to select all commits that belongs to this branch after creation from the parent branch and don’t select count of them by hands with the following:
It’s useful if you want to do that prior to merge