As I have already written in a previous post, I have moved away from bzr to git for most of my software projects (I still prefer bzr for documents, like my research papers). A lot if not most of the comparison of git vs other tools focus on speed. True, git is quite fast for source code management, but I think this kinds of miss the point of git. It took me time to appreciate it, but one of the git’s killer feature for source code control is the notion of content tracking. Bzr (and I believe hg although I could not find good information on that point) use file id, i.e. they track files, and a tree is a set of files. Git, on the contrary, tracks content, not files. In other words, it does not treat files individually, but always internally consider the whole tree.

This may seem like an internal detail, and an annoyance because it leaks at the UI level quite a lot (the so-called index is linked to this). But this means that it can record the history of **code** instead of **files** quite accurately. This is especially visible with git blame. One example: I recently started a massive surgery on the numpy C source code. Because of some C limitations, the numpy core C code was in a couple of giantic source files, and I split this into more logical units. But this breaks svn blame heavily. If you just rename a file, svn blame is lost can follow renames. But if you split one file into two, it becomes useless. Because git tracks the whole tree, the blame command can be asked to detect code moves** across files**. For example, git blame with rename detections gives me the following on one file in numpy:

dc35f24e numpy/core/src/arrayobject.c 1) #define PY_SSIZE_T_CLEAN dc35f24e numpy/core/src/arrayobject.c 2) #include <Python.h> dc35f24e numpy/core/src/arrayobject.c 3) #include "structmember.h" dc35f24e numpy/core/src/arrayobject.c 4) 65d13826 numpy/core/src/arrayobject.c 5) /*#include <stdio.h>*/ 5568f288 scipy/base/src/multiarraymodule.c 6) #define _MULTIARRAYMODULE 2f91f91e numpy/core/src/multiarraymodule.c 7) #define NPY_NO_PREFIX 2f91f91e numpy/core/src/multiarraymodule.c 8) #include "numpy/arrayobject.h" dc35f24e numpy/core/src/arrayobject.c 9) #include "numpy/arrayscalars.h" 38f46d90 numpy/core/src/multiarray/common.c 10) 38f46d90 numpy/core/src/multiarray/common.c 11) #include "config.h" 0f81da6f numpy/core/src/multiarray/common.c 12) 71875d5c numpy/core/src/multiarray/common.c 13) #include "usertypes.h" 71875d5c numpy/core/src/multiarray/common.c 14) 0f81da6f numpy/core/src/multiarray/common.c 15) #include "common.h" 5568f288 scipy/base/src/arrayobject.c 16) 65d13826 numpy/core/src/arrayobject.c 17) /* 65d13826 numpy/core/src/arrayobject.c 18) * new reference 65d13826 numpy/core/src/arrayobject.c 19) * doesn't alter refcount of chktype or mintype --- 65d13826 numpy/core/src/arrayobject.c 20) * unless one of them is returned 65d13826 numpy/core/src/arrayobject.c 21) */

You can notice that the original file can be found for every line of code in the new file. The original author and date may be found as well, I just removed them for the blog post.

This is truely impressive, and is one of the reason why git is so far ahead of the competition IMHO. This kind of features is extremely useful for open source projects, much more than rename support. I am ready to deal with quite a few (real) Git UI annoyances for this.

### Edit

It looks like my example was not very clear. I am not interested in following the renames of the file: in the example above, the file was not arrayobject.c first, then renamed to multiarraymodules.c, and later to common.c. The file was created from scratch, with content taken from those files at some point. You can try the following simplified example. First, create two files prod.c and sum.c:

#include

{

int i;

double acc = 0;

for(i = 0; i < n; ++i) {
acc += in[i];
}
return acc;
}
[/sourcecode]
[sourcecode language='c']
#include

double prod(const double* in, int n)

{

int i;

double acc = 1;

for(i = 0; i < n; ++i) {
acc *= in[i];
}
return acc;
}
[/sourcecode]
Commit to your favorite VCS. Then, you reorganize the code, and in particular you put the code of both files into a new file common.c. So you create a new file common.c:
[sourcecode language='c']#include

double prod(const double* in, int n)

{

int i;

double acc = 1;

for(i = 0; i < n; ++i) { acc *= in[i]; } return acc; } double sum(const double* in, int n) { int i; double acc = 0; for(i = 0; i < n; ++i) { acc += in[i]; } return acc; } [/sourcecode] And commit. Then, try blame. Rename tracking won't help at all, since nothing was renamed. On this very simple example, you could improve things by first renaming say sum.c to common.c, then adding the content of prod.c to common.c, but you will still loose that the prod function comes from prod.c. git blame -C -M gives me the following:

^ae7f28a prod.c 1) #include <math.h> ^ae7f28a prod.c 2) ^ae7f28a prod.c 3) double prod(const double* in, int n) ^ae7f28a prod.c 4) { ^ae7f28a prod.c 5) int i; ^ae7f28a prod.c 6) double acc = 1; ^ae7f28a prod.c 7) ^ae7f28a prod.c 8) for(i = 0; i < n; ++i) { ^ae7f28a prod.c 9) acc *= in[i]; ^ae7f28a prod.c 10) } ^ae7f28a prod.c 11) ^ae7f28a prod.c 12) return acc; ^ae7f28a prod.c 13) } ^ae7f28a sum.c 14) ^ae7f28a sum.c 15) double sum(const double* in, int n) ^ae7f28a sum.c 16) { ^ae7f28a sum.c 17) int i; ^ae7f28a sum.c 18) double acc = 0; ^ae7f28a sum.c 19) ^ae7f28a sum.c 20) for(i = 0; i < n; ++i) { ^ae7f28a sum.c 21) acc += in[i]; ^ae7f28a sum.c 22) } ^ae7f28a sum.c 23) ^ae7f28a sum.c 24) return acc; ^ae7f28a sum.c 25) }

hg blame on the contrary will tell me everything comes from common.c. Even when using the rename trick, I cannot get more than the following with hg blame -f -c:

81c4468e59f9 sum.c: #include <math.h> 81c4468e59f9 sum.c: 81c4468e59f9 sum.c: double sum(const double* in, int n) 81c4468e59f9 sum.c: { 81c4468e59f9 sum.c: int i; 81c4468e59f9 sum.c: double acc = 0; 81c4468e59f9 sum.c: 81c4468e59f9 sum.c: for(i = 0; i < n; ++i) { 81c4468e59f9 sum.c: acc += in[i]; 81c4468e59f9 sum.c: } 81c4468e59f9 sum.c: 81c4468e59f9 sum.c: return acc; 81c4468e59f9 sum.c: } 3c1ac7db76ba common.c: 3c1ac7db76ba common.c: double prod(const double* in, int n) 3c1ac7db76ba common.c: { 3c1ac7db76ba common.c: int i; 3c1ac7db76ba common.c: double acc = 1; 3c1ac7db76ba common.c: 3c1ac7db76ba common.c: for(i = 0; i < n; ++i) { 3c1ac7db76ba common.c: acc *= in[i]; 3c1ac7db76ba common.c: } 3c1ac7db76ba common.c: 3c1ac7db76ba common.c: return acc; 3c1ac7db76ba common.c: }