08 Oct 2012, 18:44

git: Rebase vs. Rebase

For a some time I’ve wondered about git rebase. At some point in the past I’ve realised that there is not one use in git rebase but (at least) two distict ones.

  • On the one hand git rebase is used to rebase a branch onto an updated source branch (source like in origin, not in source code).
  • On the other hand it’s used to rewrite commit history.

What’s rebase?

A rebase makes git rewind your commit history up to a certain point and than re-apply your patches onto another starting point. The starting point depends on the exact type of rebase you do and what you tell git.

Rebase a branch

Why would you want to rebase a branch onto another one and what does it do?

If you have a feature branch and want this to be merged with your master branch you could of course merge it. If you do so and your feature branch is not based of the last commit in master git will create a new merge commit since it has to merge two branches of a tree. If you’d rebase your feature branch onto the tip of master you’d have a linear merge history w/o a merge commit instead.

Rewrite a branch

Why would you want to rewrite your commit history? What if you make mistakes while crafting a new branch? If you’re following common VCS advice you’ll probably commit often. Probably between some mistake you’ve made and the time you did correct it.

Now you’d have your shiny new feature commit and two or more commits w/ bugfixes to your initial commit in this feature branch. Some people prefer to keep the history of their mistakes. Those could just merge this new feature branch into their master branch.

Others prefer to keep their commit history clean (you wouldn’t release a book which includes all mistakes and corrections you’ve made, would you?). Here comes git rebase -i to the rescue. This rebases the current branch onto itself. This may sound a bit silly but it allows you to drop commits or more importantly to combine (squash) commits together!

Where to got from here?

This post wasn’t meant to give a complete introduction to git rebasing. There are plenty of great tutorials out there. I did just want to highlight some points which were important to me.

02 Oct 2011, 16:13

VBoxAdm 0.1.15

I’ve just uploaded VBoxAdm 0.1.15. It includes another set of major refactorings. Please be careful when upgrading and watch your logfiles closely for any errors that may occur. Especially the Vacation module was refactored.

The time when the project will leave it’s alpha stage is drawing closer. VBoxAdm is now running on several largish sites under my direct administrative control, so I’ve got plenty of possiblities for some real-world testing. Several other migrations/installations are planned for the near future. Once it has proven sufficiently stable on these mailservers I’ll announce the the end of the alpha phase and enter beta testing.

Stay tuned!

10 Jul 2011, 16:57

GIT: Rewriting commit history - change author and email

Quicklink: How to change author and email in the whole commit History: http://theelitist.net/git-change-revision-author/

03 Feb 2010, 12:00

Setting up Gitweb on Debian

There are many blog posts and howtos about setting up gitweb on the web. Unfortunately none of those seems to work for me. Either you can’t check out via http or it’s just not working.

Here is my configuration, which works for me on Debian Lenny. If you follow this instructions you’ll get a working gitweb Webinterface, checkouts via HTTP and git URLs.

First create a new directory to hold the git repositories. I’ll use the FHS compliant /srv/git:

mkdir /srv/git

Then create a new Apache 2 Vhost:

<virtualhost *:80>
ServerName git.example.net
ServerAdmin you@example.net
SetEnv  GITWEB_CONFIG   /etc/gitweb.conf
DocumentRoot    /srv/git
ErrorLog /var/log/apache2/git.example.net-error.log
CustomLog /var/log/apache2/git.example.net-access.log combined
HostnameLookups On
UseCanonicalName Off
ServerSignature Off

Alias /gitweb.css /usr/share/gitweb/gitweb.css
Alias /git-favicon.png /usr/share/gitweb/git-favicon.png
Alias /git-logo.png /usr/share/gitweb/git-logo.png
Alias /git /srv/git

ScriptAlias /gitweb.cgi /usr/lib/cgi-bin/gitweb.cgi
DirectoryIndex gitweb.cgi
<directory /srv/git>
AllowOverride None
Options Indexes FollowSymlinks
Order Allow,Deny
Allow From All

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}         !-f
#RewriteCond %{REQUEST_FILENAME}        !-d
RewriteRule ^.* /gitweb.cgi/$0          [L,PT]
# for debugging rewrite rules
#RewriteLog /srv/www/git.gauner.org/logs/rewrite.log
#RewriteLogLevel 9

In most tutorials you’re told to include the RewriteCond matching directories (!-d), but for me that broke pretty URLs, so I disabled it.

If you use lighttpd, check out this FAQ entry.

Now you’ll need to make some adjustments to /etc/gitweb.conf:

$projectroot = "/srv/git";

# turn off potentially CPU-intensive features
$feature{'search'}{'default'} = [undef];
$feature{'blame'}{'default'} = [undef];
$feature{'pickaxe'}{'default'} = [undef];
$feature{'grep'}{'default'} = [undef];
$feature{'snapshot'}{'default'} = [undef];

# nicer-looking URLs (req. apache rewrite rules)
$feature{'pathinfo'}{'default'} = [1];

$site_name = "git.example.net";
$my_uri = "http://git.example.net";

# target of the home link on top of all pages
$home_link = $my_uri || "/";

@git_base_url_list = ("git://git.example.net");

Restart the Apache and checkout if your Vhost works.

Finally you can setup the OpenBSD inetd in /etc/inetd.conf add this line:

git     stream  tcp     nowait  nobody  /usr/bin/git-daemon git-daemon --inetd --verbose --base-path=/srv/git /srv/git

Now you’re done. Of course you need to install apache2, gitweb and openbsd-inetd but that should be clear ;)

Go here or here for more information.