Home > Net >  git merge in vscode wipes out code on master without merge conflict
git merge in vscode wipes out code on master without merge conflict

Time:02-12

My problem is that when try to do a simple git merge the branch that I am merging into loses entries but there is no merge conflict - just lost files.

This is taking place in an internal class (robot practice)

master:

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;
   }
}

robot-info

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;
  }
}

when I do 'git merge robotInfo' the RobotInfo class in master is completely overwritten by the RobotInfo class in robotInfo. It is not combined and there are no merge conflicts.

I have scoured to find any solutions but no dice. Does this have to do with it being an internal class? Usually I have run across merge conflicts, but never one where it simply discarded any issues.

What am I doing wrong?

CodePudding user response:

I do not know about VSCode, but git does not care about your internal class. So this can not happen because of that. I think it is more likely that something was deleted in the other branch and so git is doing what it should. To make it more clear: If I have branch A and B and I delete a file in branch B and then merge B into A, the file will of course also be deleted in branch A.

I would recommend:

  • Check the git log with git log --stat for both branches and see where the file was deleted
  • Check the diff between the branches with a command like git diff BranchA..BranchB
  • Related