Git日志和现实不匹配



关于我在这里的问题:Git;合并后代码消失

它又发生了,我不明白是怎么发生的。问题是,在提交中更改了一行代码,但旧的一行存在于文件的当前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—单线图

$ 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

当您提取并执行合并时,commit 2ab5fb14765caa269c027e8c57b11232b0441625删除了您进行更改的位置附近的一大块代码,git错误地使用该行的commit版本解决了合并。您可以在补丁中看到该提交的行。

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错误地解析合并。

相关内容

  • 没有找到相关文章

最新更新