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!
![Write Simple, Elegant and Maintainable Media Queries with Sass]()
I spent a few months experimenting with different approaches for writing simple, elegant and maintainable media queries with Sass. Each solution had something that I really liked, but I couldn't find one that covered everything I needed to do, so I ventured into creating my...
![Send Text Messages with PHP]()
Kids these days, I tell ya. All they care about is the technology. The video games. The bottled water. Oh, and the texting, always the texting. Back in my day, all we had was...OK, I had all of these things too. But I still don't get...
![CSS Gradients]()
With CSS border-radius, I showed you how CSS can bridge the gap between design and development by adding rounded corners to elements. CSS gradients are another step in that direction. Now that CSS gradients are supported in Internet Explorer 8+, Firefox, Safari, and Chrome...
![Highlighter: A MooTools Search & Highlight Plugin]()
Searching within the page is a major browser functionality, but what if we could code a search box in JavaScript that would do the same thing? I set out to do that using MooTools and ended up with a pretty decent solution.
The MooTools JavaScript Class
The...
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