Tag Archives: maintenance

Learn More About the History of a Line with Git Blame

I’m working on an interesting refactoring project at the moment. Today, I found a strange part in the code and I was really curious who implemented it and why, so I run git blame to learn more about it. Since I cannot share code from the customer’s repository, I’ll use the code from one of my repositories. Let’s say that the Munger.java is not working as it is supposed to work, and the test framework reports problem at line 9:

% git blame -L8,+3 src/main/java/com/zsoltfabok/blog/Munger.java
ab7e2b50 (Zsolt 2012-01-25 00:26:17 +0100  8)     public String munge(String word) {
e26fd52f (Zsolt 2012-02-07 20:45:30 +0100  9)       if (word.length() > 2) {
e26fd52f (Zsolt 2012-02-07 20:45:30 +0100 10)           return word;

It seems that the commit e26fd52f affected that line, let’ see what the change is about:

% git show e26fd52f
commit e26fd52f2de26bb087f63fd70458e75e08540a02
Author: Zsolt Fabok
Date:   Tue Feb 7 20:45:30 2012 +0100
 
    Indentation fix
 
     public String munge(String word) {
-        if (word.length() < 2) {
-            return word;
-        } else {
-            StringBuilder temp = new StringBuilder(word);
-            temp = temp.reverse();
-            return switchFirstAndLastCharacters(temp).toString();
-        }
+      if (word.length() < 2) {
+          return word;
+      } else {
+        StringBuilder temp = new StringBuilder(word);
+        temp = temp.reverse();
+        return switchFirstAndLastCharacters(temp).toString();
+      }

This is what I saw during the day: someone did and irrelevant change – indentation fix in this case -, which prevents me from learning about the change that I’m actually interested in. Fortunately, git is the best version control system on the market, and provides some help in cases like this one. Read more »

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)