The Coolest Merge EVER – My take

Linus Torvalds wrote about “The coolest merge EVER!” back in June 20051 now I needed to do something similar a while back.

I had two git repositories that I use for database backup, the two repositories contains backup from a different mysql server in a master-slave setup and therefor contains mostly the same data. This was a problem because they had grown to a size which is a pain to sync to other servers.
So I decided to join the two repositories into one with full history. Unfortunately simply doing what Torvalds had done wouldn’t work because the files in the two repositories are in the same path and with the same file names, so I had rewrite the commits so that the files were moved to an appropriate sub-directory.

For such a task git has a tool called filter-branch, which can rewrite the history according to rules I’ve made for it.
This is what I did:

### First clone the repositories
git clone path-to-first-repository database_server1
git clone path-to-second-repository database_server2

### Now that you have a clone of both repositories enter the first of them and rewrite it's history so all the files are in a subdirectory. You should also alter some of the files with sed or other cli utils.
cd database_server1
git filter-branch -f --prune-empty --tree-filter 'mkdir -p <subdirname>; find -mindepth 1 -maxdepth 1 -type f -exec mv '{}' <subdirname>/ \;;'

### Rewriting can take a very long time and requires a lot of CPU and memory, after you've done it on the first repository move on to the other repository and repeat the process by moving the files to different directory.
cd ../database_server2
git filter-branch -f --prune-empty --tree-filter 'mkdir -p <subdirname>; find -mindepth 1 -maxdepth 1 -type f -exec mv '{}' <subdirname>/ \;;'

### Now that you have rewritten the history of both repositories make a clone of the first one, so you don't have to start from scratch if something goes wrong.
cd ..
git clone database_server1 database_server1_merge
cd database_server1_merge

### And now for "The Coolest Merge EVER", I've taken the liberty to fix the commands so they work with a resent version of git.
git fetch ../database_server1
GIT_INDEX_FILE=.git/tmp-index git read-tree FETCH_HEAD
GIT_INDEX_FILE=.git/tmp-index git checkout-index -a -u
git update-index --add -- (GIT_INDEX_FILE=.git/tmp-index git ls-files)
cp .git/FETCH_HEAD .git/MERGE_HEAD
git commit
git gc --prune=now # Clean out old objects if needed.

That’s it, now I have a single git repository with the full history of the two original repositories

KRegExpEditor

Inspired by some patches I found on kde-apps, I’ve started working on the great KDE application KRegExpEditor, developed by Jesper K. Pedersen from blackie.dk.

I don’t have commit access to KDEs repositories and KRegExpEditor is still in the old SVN-repository, so I’ve created a temporary project on gitorious located here http://gitorious.org/kregexpeditor/kregexpeditor

The first thing I’ll do is fixing some of the bugs and crashes. I’ve applied the patches from http://kde-apps.org/content/show.php/KRegExpEditor+and+KDE4?content=144569 and I’ve fixed a crash, that was triggered when I switched to emacs syntax.

Now a Supporting member of KDE e.V.

And now to something I’ve very passionate about, OpenSource and specifically KDE.

A few months back KDE e.V. started the “Join the Game”-campaign1,
asking people to give financial support to the KDE project. And as I’ve loved KDE for almost as long as I’ve been using Linux, I decided to join the game and give 25€ per quarter to KDE e.V.

Back in October I received a gift from KDE e.V. along with the welcome-letter for the organization. I”ve posted pictures of it on http://frifantasi.dk/index.php/Join-the-Game :)

I love KDE, well I love KDE as much as it’s possible to love a piece of software and what a piece it is :) .
The KDE Software Compilation (KDE SC) is a large collection of software, that I use on a daily basis, from the KDE desktop to many of the applications provided by KDE and related projects like Amarok. I even use KDE Apps under Mac OSX, especially Okular2.

I do hope that I at some point can contribute something more than just a few € to the project, in form of some more code or translations3,
but at the moment this is all I can do.

If you too like KDE and want to support it with a few € please go join the game at http://jointhegame.kde.org/.

  1. http://jointhegame.kde.org/ []
  2. Okular is KDE’s document-viewer with some very useful feature, that I’ve grown depended on []
  3. I’ve previously submitted patches to Kopete and Amarok, and I translated KDevelop 4.0 to Danish in time for the 4.0 release. []