0

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).

4

2 回答 2

1

假设您指的是两条线范围线(@@ class ...)并且您已添加了星星(顺便说一句,这非常令人困惑,您应该真的已经解释了问题中的问题):

在统一差异格式的行范围之后有文本是可以接受的。Git 就是这样做的,所以处理它是你的工作。http://en.wikipedia.org/wiki/Diff#Unified_format

于 2013-03-24T06:53:38.167 回答
0

为避免随机间距引入虚假差异,请进行空白清理(即,所有制表符或所有空格,行尾没有空格,文件末尾没有空行,所有文件都以换行符结束)。可能您会想要git config apply.whitespace fix,并且可能会深入挖掘修复此问题的历史。

于 2013-03-24T19:38:58.130 回答