2016-09-02

following code through history, in subversion and git

Both, git and subversion, have the famous "blame" command, which allows me to see, line by line, who changed this line of code last.

Sometimes it is not the latest modifier of a line who is its true author. For example when a programmer added or removed whitespace for better readability, she will then be "blame"d as it's author, even though she is not.

In this case, it is possible to give the blame command an additional agrument, saying "look at the file in this revision, and tell me who brought it up to that state, line by line".

in subversion:

$svn blame filename
   649     joe  today's code
$svn blame filename -r648
  171     jim previous code
$svn blame filename -r170
 svn: Unable to find repository location for 'filename' in revision 170

in git:

$ git blame filename
3c9fb2a17 (Joe 2016-09-01 16:43:11 +0200 1) today's code
$ git blame filename 3c9fb2a17^
 98bcec40b (Jack 2016-06-23 18:04:55 +0200 1) previous code
$ git blame filename 98bcec40b^
fatal: no such path filename in 98bcec40b^

Note the caret (^) you have to add to the end of the git hash. It means "the previous commit from that designated by the hash". In subversion, where everything is nicely ordered, you simply subtract one in order to get the same effect.

One day I might write a script that traces the history of a single line of code back to its creation. Please tell me if this has already been done.

No comments:

Post a Comment