【问题标题】:Error: "patch does not apply" when editing a hung in patch mode错误:在补丁模式下编辑挂起时出现“补丁不适用”
【发布时间】:2023-11-16 21:58:01
【问题描述】:

我想通过编辑以交互方式添加这个挂起:

@@ -55,3 +50,28 @@
   {
-    if(n_arguments == 1)
+    inputed_command = get_line(); //gets the user's input line from the stdin.
+
+    //we edit the user's input as needed according to qtp rules.
+    /*STRING EDITING FUNCTIONS*/
+    replace_string_chars(inputed_command, 9, ' ');
+    remove_char(inputed_command, 13);
+    remove_comments(inputed_command);
+    remove_extra_spaces(inputed_command);
+    uncapitalize(inputed_command);
+    /*END OF STRING EDITING FUNCTIONS*/
+
+    //the command gets seperated from the user's input ex. playmove w c3, here the command is playmove.
+    command = command_decode(inputed_command);
+    //the arguments are seperated from the user's input in an 2D array ex. playmove w c3, here the arguments are w and c3.
+    arguments = arguments_decode(inputed_command, &n_arguments);
+
+    //the user specified command is executed by matching the user's command with the engine's available commands. if the user's command is not one of the engine's known commands then a descriptive error is printed.
+    if(strcmp(command, "name") == 0)
+      name();
+    else if(strcmp(command, "known_command") == 0)
+      known_command(arguments, n_arguments);
+    else if(strcmp(command, "list_commands") == 0)
+      list_commands();
+    else if(strcmp(command, "quit") == 0)
+      quit(&quit_game);
+    else if(strcmp(command, "boardsize") == 0)
     {

我只想上演这部分:

@@ -55,3 +50,28 @@
   {
-    if(n_arguments == 1)
+    inputed_command = get_line(); //gets the user's input line from the stdin.
+
+    //we edit the user's input as needed according to qtp rules.
+    /*STRING EDITING FUNCTIONS*/
+    replace_string_chars(inputed_command, 9, ' ');
+    remove_char(inputed_command, 13);
+    remove_comments(inputed_command);
+    remove_extra_spaces(inputed_command);
+    uncapitalize(inputed_command);
+    /*END OF STRING EDITING FUNCTIONS*/
+
+    //the command gets seperated from the user's input ex. playmove w c3, here the command is playmove.
+    command = command_decode(inputed_command);
+    //the arguments are seperated from the user's input in an 2D array ex. playmove w c3, here the arguments are w and c3.
+    arguments = arguments_decode(inputed_command, &n_arguments);
+
     {

但是当我保存并退出时,会出现“补丁不适用”的错误。

我读到我需要编辑 @@ 字符之间的数字,但我从来没有做对。请描述一下如何解决这个错误,谢谢。

【问题讨论】:

    标签: git add edit patch interactive


    【解决方案1】:

    这看起来像是从补丁中删除“+”行的简单案例。我看到的唯一可能导致你的补丁失败的是最后一个花括号在你的两个大块中缩进不同。

    在您编辑补丁时,您的编辑器是否应用了自动格式化规则?

    【讨论】:

    • 我删除了不需要的添加行和不合适的花括号,但仍然出现相同的错误。不,我认为我的编辑器没有应用自动格式设置规则。
    • @PlatwnAce 这对我来说也很像。大括号缩进在原始文件中看起来是错误的。 (如果这只是发布到 * 的人工制品,请修复它。在这类问题中,逐个字符的准确性很重要。)
    • @Kaz 是的,它是一个人工制品。对困惑感到抱歉。现在已经修好了。
    • @PlatwnAce 将空格扩展到制表符之类的怎么样?如果你正在做git add --patch,你应该能够在编辑一个大块时删除+ 行。事实上,您也可以添加 + 行。 (这些不会转到您的工作副本;它们仅在暂存索引中。)
    • 当我删除 + 行时,我得到了错误。有空格而不是制表符这一事实不会影响结果。
    最近更新 更多