How to merge massive formatting-only commits between git branches

*** As always, first backup everything (your git working directory etc.) ***

Let’s assume formatting changed in branch A, and you’re working in branch B

To make life easier, prepare two git clones, the other one is checked out
with branch A (in dir gitA), the other one with branch B (in dir gitB).
You need to have both branches in gitB up-to-date, so:

gitB> checkout A
gitB> git pull
gitB> checkout B
gitB> git pull

Let’s assume the formatting-only megacommit has hashcode AAAA and the commit
before that has hashcode BBBB. You can check the latest commits to
branch A like this:

gitA> git log | less

First, merge A to B until the last commit before the formatting-only commit.

gitB> git merge BBBB

Do the usual merge-stuff and commit. Do not push. For later analysis store
the changed filenames:

gitB> git diff --name-only A > ../diffsbeforemerge

Close Eclipse or other clever software that is holding to your git working clone.

Clean:

gitB> git clean -d -x -f .

Copy all files to a safe place, e.g.

gitB> cd ..
xxxx> tar cf gitB.tar gitB

Create another tar file without .git directory:

xxxx> cp gitB.tar gitB-nogit.tar
xxxx> tar --delete -f gitB-nogit.tar gitB/.git

Merge the formatting-only megacommit (hashcode AAAA):

xxxx> cd gitB
gitB> git merge AAAA

Don’t worry about any conflicts… Just copy over the old files:

gitB> cd ..
xxxx> tar xf gitB-nogit.tar

At this point, format all source codes with the same formatter as in branch A,
e.g. by starting Eclipse and importing the correct formatter and then selecting
all projects and ‘Source/Format’.

Then:

xxxx> cd gitB
gitB> git add *
gitB> git commit -m "Synchronized formatting with branch A."

Now it is a good time to check what was changed before you push your changes
anywhere. Remember that you have the backup of the situation before merging,
so you can just wipe away the gitB directory and extract the tarball gitB.tar.

You can check that the formatting-only-merge did not add any new diffs to
branches:

gitB> git diff --name-only A > ../diffsaftermerge
gitB> diff -u ../diffsbeforemerge ../diffsaftermerge
Facebooktwitterredditpinterestlinkedinmail

Moved to DigitalOcean

After running my external web site and e-mail on a “webhotel” (at www.louhi.fi) for five years, I got fed up to the inflexibility of the solution and started to look for VPS (Virtual Private Server) options.

Five years ago, a VPS was still quite expensive, but as the prices seem to have dropped, they are no longer much more expensive than webhotels. My colleague recommended DigitalOcean so I decided to give it a shot. At first glance, it looked perfect: the smallest VPS has 1 CPU, 512 MB RAM, 20 GB HD and 2 TB monthly traffic, static IPv4 and IPv6 address. Their web interface is very clean and efficient. Registering and setting up a Debian 8 “droplet” only took about two minutes. I got the root password by e-mail and was ready to SSH in. It seems extremely easy and user-friendly compared to e.g. Amazon. It is also much cheaper – just 5 dollars per month. (For more dynamic setups, they offer an API and hour-based charging as well – so that you can e.g. create large Linux clusters on demand automatically from your own software.)

Luckily I had saved the old configurations from the VPS I was running before the webhotel era, so I didn’t have to configure everything from scratch. After spending a couple of evenings with my laptop, I now have my e-mail (postfix, dovecot, sieve, spamassassin) and website (apache, wordpress) running 24/7 in DigitalOcean’s data center in Amsterdam. I run automatic backups over SSH to my home server each night. I also moved rinta-aho.org DNS servers to DigitalOcean. They have a very neat web page to configure the DNS records and they don’t charge any extra for that.

After a few weeks, I am very happy with the change. I now pay less than I paid for the webhotel, I have more disk space, I have complete control over the software running on my server, and all services at rinta-aho.org are now accessible through IPv6.

Give it a try: https://www.digitalocean.com/?refcode=44faab0c4f59

Facebooktwitterredditpinterestlinkedinmail