Git日志和现实不匹配

时间:2013-07-10 12:27:59

标签: git git-commit

关于我的问题:Git; code disappeared after merge

又发生了,我不明白怎么回事。问题是,在提交中更改了一行代码,但旧文件存在于文件的当前repo版本中,这看起来很奇怪。有没有人对这种情况有什么了解,以及我们如何避免它?

有问题的行是create_marking方法的函数头

更改行的提交(按预期方式):

commit 925ec3c11006ccca37cf684443d0fad3e1781dca
Author: xxxx
Date:   Tue Jun 4 14:55:52 2013

    Comment

diff --git a/lib/services/MarkingService.class.php b/lib/services/MarkingService.class.php
index 66a33f7..acf830a 100644
--- a/lib/services/MarkingService.class.php
+++ b/lib/services/MarkingService.class.php
@@ -34,18 +34,12 @@ class MarkingService \{
         return '[' . implode(',', self::getCoordinates($marking)) . ']';
     \}
\}

-    public function create_marking($category, $timestamp, $field_id, $lat, $lon, $accuracy, $lat2 = null, $lon2 = null, $accuracy2 = null, $spread = null, $depth = null, $comment = null) \{
+    public function create_marking($category, $timestamp, $field_id, $coordinates, $spread = null, $depth = null, $comment = null) \{
         $this->validate_category($category);
         $this->validate_timestamp($timestamp);

接下来的两个提交是历史上的唯一提交,在上面的提交之后,据我所知,它们不会以任何方式改变相关的行:

commit 2ab5fb14765caa269c027e8c57b11232b0441625
Author: xxx
Date:   Thu Jul 4 13:58:26 2013

    Comment

diff --git a/lib/services/MarkingService.class.php b/lib/services/MarkingService.class.php
index 66a33f7..c553876 100644
--- a/lib/services/MarkingService.class.php
+++ b/lib/services/MarkingService.class.php
@@ -8,32 +8,6 @@ class MarkingService {
         return $instance;
     }

-    public static function getCoordinates(lmMarking $marking)
-    {
-        $returnValue = array($marking->getLatitude() . ',' . $marking->getLongitude());
-        
-        if (0 < $marking->getLatitude2()) {
-            $returnValue[] = $marking->getLatitude2() . ',' . $marking->getLongitude2();
-        }
-        
-        return $returnValue;
-    }
-    
-    public static function getCoordinatesJavascript(lmMarking $marking)
-    {
-        return '[' . implode(',', self::getCoordinates($marking)) . ']';
-    }
-
     public function create_marking($category, $timestamp, $field_id, $lat, $lon, $accuracy, $lat2 = null, $lon2 = null, $accuracy2 = null, $spread = null, $depth = null, $comment = null) {
         $this->validate_category($category);
         $this->validate_timestamp($timestamp);

commit d152befa9977b8fc13df9f3ea3f756217751cb0d
Merge: 77b20e2 2ab5fb1
Author: xxx
Date:   Thu Jul 4 14:43:26 2013

    Comment

diff --cc lib/services/MarkingService.class.php
index acf830a,c553876..f5a8bc4
--- a/lib/services/MarkingService.class.php
+++ b/lib/services/MarkingService.class.php
@@@ -131,34 -157,4 +105,34 @@@ class MarkingService 
              throw new InvalidArgumentException("Invalid depth: '$depth'");
          }
      }
 +    
 +    private function validateCoordinates($coordinates)
 +    {
 +        $validatorOptions = array(
 +            'lat' => array(
 +                'field' => 'latitude',
 +                'validator' => FILTER_VALIDATE_FLOAT
 +            ),
 +            'lng' => array(
 +                'field' => 'longitude',
 +                'validator' => FILTER_VALIDATE_FLOAT
 +            ),
 +            'accuracy' => array(
 +                'field' => 'accuracy',
 +                'validator' => FILTER_VALIDATE_INT
 +            )
 +        );
 +        
 +        foreach ($coordinates as $coordinate) {
 +            foreach ($coordinate as $key => $value) {
 +                if (false === filter_var($coordinate[$key], $validatorOptions[$key]['validator'])) {
 +                    throw new InvalidArgumentException("Invalid " . $validatorOptions[$key]['field'] . ": '" . $value . "'");
 +                }
 +            }
 +        }
 +    }
- }
+ }

由于某些原因我无法理解,文件中的行现在读取

public function create_marking($category, $timestamp, $field_id, $lat, $lon, $accuracy, $lat2 = null, $lon2 = null, $accuracy2 = null, $spread = null, $depth = null, $comment = null) {

我做错了什么?

修改 输出git状态

$ git status
# On branch master
nothing to commit, working directory clean

输出git log

$ git log lib/services/MarkingService.class.php
commit d152befa9977b8fc13df9f3ea3f756217751cb0d
Merge: 77b20e2 2ab5fb1
Author: xxx
Date:   Thu Jul 4 14:43:26 2013 +0300

    Changed the format of Markings block in Sync API method.
    Send markings coordinates in the API in the new format

commit 2ab5fb14765caa269c027e8c57b11232b0441625
Author: xxx
Date:   Thu Jul 4 13:58:26 2013 +0300

    Changed the format of Markings block in Sync API method.
    Send markings coordinates in the API in the new format

commit 925ec3c11006ccca37cf684443d0fad3e1781dca
Author: xxx
Date:   Tue Jun 4 14:55:52 2013 +0300

    Changed the makrings coordinates structure.
    Allow more points in CreateMarking

git log --oneline --graph

$ git log --oneline --graph lib/services/MarkingService.class.php
*   d152bef Changed the format of Markings block in Sync API method. Send markings coordinates in the API in the new format
|\
| * 2ab5fb1 Changed the format of Markings block in Sync API method. Send markings coordinates in the API in the new format
* | 925ec3c Changed the makrings coordinates structure. Allow more points in CreateMarking
|/
* bacfb14 An intermediate commit. HOTFIX: Fix markings
* 6479513 LETFARM-1863 DB and API support for markings

1 个答案:

答案 0 :(得分:3)

当您拉动并完成合并时,提交2ab5fb14765caa269c027e8c57b11232b0441625删除了您进行更改的位置附近的大量代码,并且git错误地使用该提交版本的行解决了合并。您可以在修补程序中看到该提交的行。

Git没有跟踪线路变化。它跟踪给定点的文件状态。

  

Git没有想到或以这种方式存储数据。相反,Git认为   其数据更像是迷你文件系统的一组快照。一切   你提交的时间,或者在Git中保存你的项目状态   基本上可以了解所有文件的外观   片刻并存储对该快照的引用。要有效率,如果   文件没有改变,Git不再存储文件 - 只是一个链接   到之前存储的相同文件。

http://git-scm.com/book/en/Getting-Started-Git-Basics

因此,Git看到您提交的提交甚至更改为您修改的行,并通过选择行来“解析”合并。

我之前已经看到过这种情况,并且通常是由于删除/重新排序恰好发生其他更改的大块代码所致。我建议您在更新本地分支时使用git pull --rebasegit rebase

http://git-scm.com/book/en/Git-Branching-Rebasing

这会将您的本地提交移到已经在遥控器上的任何设备之后,如果git难以应用提交,则会要求您更改提交。这也使历史保持线性,并且不会让git解析合并错误。