fer
fer

Reputation: 123

error in git log

So I have been coming into this git log error several times now.

I wrote this simple java code to illustrate it. I commit my progress (writing it gradually) and then run git log -p --decorate

class Mega {
    private int alpha = 0;
    private int beta = 1;
    private int omega = 5;

    public returnAlpha(){
        return this.alpha;
    }

    public returnBeta(){
        return this.beta;
    }

    public returnOmega(){
        return this.omega;
    }
}

This is the git log:

commit 2dcc5243a943a7e1a3344479bfb6a21474c6c024 (HEAD, master)
Date:   Sat Mar 23 17:26:24 2013 -0700

    stage 2

diff --git a/untitled.java b/untitled.java
index 821a19e..b2ba345 100644
--- a/untitled.java
+++ b/untitled.java
**@@ -10,4 +10,8 @@ class Mega {**
    public returnBeta(){
        return this.beta;
    }
+
+   public returnOmega(){
+       return this.omega;
+   }
 }
\ No newline at end of file

commit 43fadfc5ec827cf24667494e350ca9bcda21ffd3
Date:   Sat Mar 23 17:26:01 2013 -0700

    stage 2

diff --git a/untitled.java b/untitled.java
index e5c38d9..821a19e 100644
--- a/untitled.java
+++ b/untitled.java
**@@ -6,4 +6,8 @@ class Mega {**
    public returnAlpha(){
        return this.alpha;
    }
+
+   public returnBeta(){
+       return this.beta;
+   }
 }
\ No newline at end of file

commit 46d27d8485cb296798e5490803b1b7a04313793f
Date:   Sat Mar 23 17:25:24 2013 -0700

    stage 1

diff --git a/untitled.java b/untitled.java
index 332a406..e5c38d9 100644
--- a/untitled.java
+++ b/untitled.java
@@ -1,5 +1,9 @@
 class Mega {
-   int alpha = 0;
-   int beta = 1;
-   int omega = 5;
+   private int alpha = 0;
+   private int beta = 1;
+   private int omega = 5;
+
+   public returnAlpha(){
+       return this.alpha;
+   }
 }
\ No newline at end of file

commit bb18a576d44b492e50906d3eac495956590ff263
Date:   Sat Mar 23 17:24:22 2013 -0700

    stage 0

diff --git a/untitled.java b/untitled.java
index e69de29..332a406 100644
--- a/untitled.java
+++ b/untitled.java
@@ -0,0 +1,5 @@
+class Mega {
+   int alpha = 0;
+   int beta = 1;
+   int omega = 5;
+}
\ No newline at end of file

commit d630ed1f1edff608488938ec3ea748a2d5a7bab1
Date:   Sat Mar 23 17:23:39 2013 -0700

    java added

diff --git a/untitled.java b/untitled.java
new file mode 100644
index 0000000..e69de29

I need to fix this log mistake because I am automatically (with a script) parsing the log and I need it to remain consistent.

Furthermore as the amount of commits increases there are other inconsistencies such as random spaces and sometimes the line after the @ is actually part of the diff (unlike the cases of this example).

Upvotes: 0

Views: 298

Answers (2)

vonbrand
vonbrand

Reputation: 11831

To avoid random spacing introducing spurious differences, do a whitespace cleanup (i.e., either all tabs or all spaces, no spaces at the end of lines, no blank lines at the end of the file, end all files with newline). Probably you'll want git config apply.whitespace fix, and perhaps go digging into the history fixing this.

Upvotes: 0

sylvain.joyeux
sylvain.joyeux

Reputation: 1699

Assuming that what you are referring to are the two line range lines (@@ class ...) and that the stars have been added by you (this is highly confusing, by the way, you should really have explained the problem in the question):

It is acceptable to have text after the line ranges in the unified diff format. Git just does that, so it is your job to deal with it. http://en.wikipedia.org/wiki/Diff#Unified_format

Upvotes: 1

Related Questions