2

ここでの私の質問に関連して: Git; マージ後にコードが消えた

それは再び起こりました、そして私はその方法を理解していません。問題は、コミットでコード行が変更されたが、古い行がファイルの現在のリポジトリ バージョンに存在することです。これは非常に奇妙に思えます。これがどのように起こっているのか、そしてそれをどのように回避するのかについて、誰か洞察を持っていますか?

問題の行は 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);

これらの次の 2 つのコミットは、上記のコミットの後、歴史の中で唯一のコミットであり、私が知る限り、問題の行を変更することは決してありません。

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 ログの出力

$ 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 ログ --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
4

1 に答える 1

3

プルしてマージを実行する2ab5fb14765caa269c027e8c57b11232b0441625と、変更を加えた場所の近くにあるコードの大部分が commit によって削除され、git は誤ってそのコミット バージョンの行を使用してマージを解決しました。そのコミットのパッチの行を確認できます。

Git は行の変更を追跡しません。特定の時点でのファイルの状態を追跡します。

Git は、このようにデータを考えたり保存したりしません。代わりに、Git はそのデータをミニ ファイル システムの一連のスナップショットのように考えています。Git でプロジェクトの状態をコミットまたは保存するたびに、基本的にその時点ですべてのファイルがどのように見えるかを撮影し、そのスナップショットへの参照を保存します。効率的にするために、ファイルが変更されていない場合、Git はファイルを再度保存しません。既に保存されている以前の同一ファイルへのリンクだけです。

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

そのため、Git は、変更した行に対する変更として取り込んだコミットを確認し、その行を選択してマージを「解決」しています。

私はこれが以前に発生するのを見たことがありますが、通常は、他の変更が発生した場所の近くにあるコードの大きなチャンクを削除/再注文するために発生します。これを回避するための私の推奨事項は、ローカル ブランチを更新するときにgit pull --rebaseまたはを使用することです。git rebase

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

これにより、既にリモートにあるコミットの後にローカル コミットが移動されます。git がコミットを適用するのが難しい場合は、コミットを変更するように求められます。これにより、履歴が線形に保たれ、git がマージを誤って解決することもありません。

于 2013-07-10T13:44:54.827 に答える