Git Tip: merge -no-squash

Often, when I develop a feature, I push to a temporary repository on Github very frequently. As an example, for implementing Fluid caching, we did around 60 commits to the GitHub repository for implementing this feature.

However, when pushing it to the TYPO3 Review System, we only want a single commit instead of many. There are two ways to achieve this, which I want to highlight here:

git rebase –interactive

If you have a quite linear history, you can do an interactive rebase, as described in this tutorial, and then squash all commits into a single one.

This works especially nice with a mostly-linear history.

The Problem: In-Between Merge Commits

While the above concept works nicely in many cases, in our example we had a non-linear history, as we merged updates from the official Fluid repository into our development branch.

Now, this meant I could not just use squash all my commits into one, but needed a different technique. When reading the man page of git merge, I found a solution:

git merge –no-squash

git checkout master
git merge --no-squash dev
# delete .git/MERGE_HEAD if it exists
git commit

The trick is to use git merge –no-squash, as it just updates the staging area but does not commit the merge yet. It thus gives you all changes; and by deleting the MERGE_HEAD file, git will commit all changes as single commit.

You of course loose connection to the intermediate commits in the dev branch then, so make sure to record at which point in the dev branch you merged back!