git merge in vscode 擦除 master 上的代码而没有合并冲突

git merge in vscode wipes out code on master without merge conflict

我的问题是当尝试做一个简单的 git 合并我正在合并的分支时丢失了条目但是没有合并冲突 - 只是丢失了文件。

这发生在内部 class(机器人练习)

大师:

public final class Constants {

   public static final class DriveInfo {
      public static final int LEFT_FRONT_DRIVE_MOTOR_ID = 1;
      public static final int LEFT_REAR_DRIVE_MOTOR_ID = 2;
      public static final int RIGHT_FRONT_DRIVE_MOTOR_ID = 4;
      public static final int RIGHT_REAR_DRIVE_MOTOR_ID = 3;

      public static final MotorType DRIVE_MOTOR_BRUSHED_TYPE = MotorType.kBrushed;

      public static final boolean LEFT_DRIVE_MOTORS_ARE_INVERTED = true;
      public static final boolean RIGHT_DRIVE_MOTORS_ARE_INVERTED = false;

      public static final double DIFFERENTIAL_DRIVE_DEADBAND = 0.08;

      public static final int LEFT_DRIVE_ENCODER_CHANNEL_A = 0;
      public static final int LEFT_DRIVE_ENCODER_CHANNEL_B = 1;
      public static final int RIGHT_DRIVE_ENCODER_CHANNEL_A = 2;
      public static final int RIGHT_DRIVE_ENCODER_CHANNEL_B = 3;

      public static final EncodingType DRIVE_MOTOR_ENCODER_ENCODINGTYPE = EncodingType.k2X;
   }

   public static final class RobotInfo{
      public static int MECHANISM_CONTROLLER_ID = 0;
      public static int DRIVE_CONTROLLER_ID = 1;
   }
}

机器人信息

public final class Constants {

   public static final class DriveInfo {
      public static final int LEFT_FRONT_DRIVE_MOTOR_ID = 1;
      public static final int LEFT_REAR_DRIVE_MOTOR_ID = 2;
      public static final int RIGHT_FRONT_DRIVE_MOTOR_ID = 4;
      public static final int RIGHT_REAR_DRIVE_MOTOR_ID = 3;

      public static final MotorType DRIVE_MOTOR_BRUSHED_TYPE = MotorType.kBrushed;

      public static final boolean LEFT_DRIVE_MOTORS_ARE_INVERTED = true;
      public static final boolean RIGHT_DRIVE_MOTORS_ARE_INVERTED = false;

      public static final double DIFFERENTIAL_DRIVE_DEADBAND = 0.08;

      public static final int LEFT_DRIVE_ENCODER_CHANNEL_A = 0;
      public static final int LEFT_DRIVE_ENCODER_CHANNEL_B = 1;
      public static final int RIGHT_DRIVE_ENCODER_CHANNEL_A = 2;
      public static final int RIGHT_DRIVE_ENCODER_CHANNEL_B = 3;

      public static final EncodingType DRIVE_MOTOR_ENCODER_ENCODINGTYPE = EncodingType.k2X;
   }

   public static final class RobotInfo{
      private static final double DRIVE_WHEEL_DIAMETER = 6.0;
      private static final double WHEEL_CIRCUMFERENCE_IN_INCHES = DRIVE_WHEEL_DIAMETER * Math.PI;
      private static final double DRIVE_ENCODER_CLICKS_PER_ROTATION = 2048.0;
      public static final double CLICKS_PER_INCH = 
          WHEEL_CIRCUMFERENCE_IN_INCHES / DRIVE_ENCODER_CLICKS_PER_ROTATION;

      private static final double INCHES_WIDTH_OF_AXLE = 22.0;
      private static final double INCHES_LENGTH_OF_AXLE = 24.0;
      private static final double DIAGONAL_INCHES_BETWEEN_AXES = 
          Math.sqrt((INCHES_WIDTH_OF_AXLE * INCHES_WIDTH_OF_AXLE) + (INCHES_LENGTH_OF_AXLE * INCHES_LENGTH_OF_AXLE));
      private static final double ROBOT_ROTATION_CIRCUMFERENCE = DIAGONAL_INCHES_BETWEEN_AXES * Math.PI;
      public static final double DRIVE_ENCODER_CLICKS_PER_DEGREE = 
          ROBOT_ROTATION_CIRCUMFERENCE / CLICKS_PER_INCH / 360;
  }
}

当我执行 'git merge robotInfo' 时,master 中的 RobotInfo class 被 robotInfo 中的 RobotInfo class 完全覆盖。它没有合并,也没有合并冲突。

我已经搜索过任何解决方案,但没有找到。这与它是内部 class 有关系吗?通常我有 运行 跨合并冲突,但从来没有一个它简单地丢弃任何问题。

我做错了什么?

我不知道 VSCode,但是 git 不关心你的内在 class。因此,这不可能发生。我认为更有可能是在另一个分支中删除了某些内容,因此 git 正在做它应该做的事情。 说得更清楚一点:如果我有分支A和B,我在分支B删除了一个文件,然后将B合并到A,那么分支A中的文件当然也会被删除。

我会推荐:

  • 使用 git log --stat 检查两个分支的 git 日志,并查看文件被删除的位置
  • 使用 git diff BranchA..BranchB
  • 这样的命令检查分支之间的差异