Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是什么导致git应用;损坏的补丁?“;_Git_Patch - Fatal编程技术网

是什么导致git应用;损坏的补丁?“;

是什么导致git应用;损坏的补丁?“;,git,patch,Git,Patch,(说来话长……) 我正在将一个巨大的PHP应用程序带到本世纪…;-)。。。而其他团队则继续维护现有版本的it 到目前为止,这已经导致了大约275个补丁。问题是,我们所做的更改之一是转换tl;dr:我怀疑您在转换一行时删除了一行结尾,该行仅由组成。为了追求Edward对这个问题的最佳答案,我仔细查看了“before”和“after”补丁文件。我还不确定我的正则表达式是如何做到这一点的,但很明显,这里是它所做的: 原始修补程序文件: <? -if ((STORES_ID == 10) &

(说来话长……)

我正在将一个巨大的PHP应用程序带到本世纪…;-)。。。而其他团队则继续维护现有版本的it


到目前为止,这已经导致了大约275个补丁。问题是,我们所做的更改之一是转换tl;dr:我怀疑您在转换一行时删除了一行结尾,该行仅由
组成。为了追求Edward对这个问题的最佳答案,我仔细查看了“before”和“after”补丁文件。我还不确定我的正则表达式是如何做到这一点的,但很明显,这里是它所做的:

原始修补程序文件:

<?
-if ((STORES_ID == 10) && (in_array($products_id, $bwFreePlaqueIDList2016))) { ?>
+if (((STORES_ID == 10) || (STORES_ID == 26)) && (in_array($products_id, $bwFreePlaqueIDList2016))) { ?>


非常真诚和热情的感谢所有帮助我解决这个问题的人。(尤其是爱德华,他刚刚向我们大家详细解释了这些补丁文件的实际格式!)

我在尝试粘贴(Ctrl+C->Ctrl+V)补丁时遇到了这个错误:

它会告诉我最后一行的补丁已经损坏


解决方案是在使用Ctrl+D结束输入之前添加一个Enter。它缺少了最后一个空行。

以下是我如何处理这个问题的

  • 我对一些文件做了一些修改,然后我发现我应该撤销对一个文件的修改
  • 我试图签出该文件,但我忘了指定该文件,我使用的是
    git checkout.
  • 在签出之前,我执行
    git diff
    查看修改,因此我从控制台复制diff输出并创建补丁文件
  • 然后我git应用补丁文件,我得到了这个问题
  • 如何修复它。
    检查从dos到unix的修补程序文件格式。(通过vim,
    set ff=unix

    补丁文件是否包含sha1散列?我不确定要查找什么。你能告诉我在补丁文件中这样的东西会是什么样子吗?是否可以告诉apply忽略任何此类散列?(我知道一个补丁可能包含一个反腐败检查……但是,如果它包含,我想在这种情况下忽略它。)你能发布一个腐败补丁的例子吗?补丁添加到帖子的文本中。命令是git apply--check-v--directory=foobar
    。我曾希望
    -v
    选项能告诉我更多关于损坏的内容,但事实并非如此。在我的情况下,损坏的补丁在其他空上下文行中缺少空格(实际更改周围以
    +
    -
    前缀的行显然必须有一个前导空格,即使它们是空的)。它还错过了最后一次换行。这个空白被GitHub删除了(我从一个注释中复制了一个diff并粘贴到一个文本文件中)。。。“向上投票”按钮只工作一次:-“无价之宝!”现在,让我花半个小时来吸收你刚才说的话“啊,我看到了一些…”问题是您的
    \s*
    \n
    匹配。积极的前瞻是好的。要么不匹配换行符,要么使用
    (\s*)
    并将匹配项嵌入替换项中。这解决了我的问题。在运行
    git diff
    之后从终端进行复制时,在进行选择时,确实要在提示符的第一个字母之前获取最后一个换行符。
    @@ -186,7 +186,7 @@ function doRequestComplete() {
    
      context:         }
      context:     }
      context:  <?php -if ((STORES_ID == 10) && (in_array($products_id, $bwFreePlaqueIDList2016))) { ?>
    postimage: +if (((STORES_ID == 10) || (STORES_ID == 26)) && (in_array($products_id, $bwFreePlaqueIDList2016))) { ?>
      context:  function doCheckBW2016PlaqueProperty() {
      context:     thePropertyNumber = document.getElementById('propertyToCheck');
      context:     if (thePropertyNumber.value == "") {
    
    @@ -186,7 +186,7 @@ function doRequestComplete() {
           }
       }
     <?php
    -if ((STORES_ID == 10) && (in_array($products_id, $bwFreePlaqueIDList2016))) { ?>
    +if (((STORES_ID == 10) || (STORES_ID == 26)) && (in_array($products_id, $bwFreePlaqueIDList2016))) { ?>
     function doCheckBW2016PlaqueProperty() {
        thePropertyNumber = document.getElementById('propertyToCheck');
        if (thePropertyNumber.value == "") {
    
    <?
    -if ((STORES_ID == 10) && (in_array($products_id, $bwFreePlaqueIDList2016))) { ?>
    +if (((STORES_ID == 10) || (STORES_ID == 26)) && (in_array($products_id, $bwFreePlaqueIDList2016))) { ?>
    
     <?php -if ((STORES_ID == 10) && (in_array($products_id, $bwFreePlaqueIDList2016))) { ?>
    +if (((STORES_ID == 10) || (STORES_ID == 26)) && (in_array($products_id, $bwFreePlaqueIDList2016))) { ?>
     function doCheckBW2016PlaqueProperty() {
    
    $content = preg_replace('/\<\?\s*(?=[^xp=])/', '<?php ', $content);
    
    $content = preg_replace('/\<\?(?=[^xp=])/', '<?php', $content);
    
    $ git patch
    [Ctrl+Shift+V to paste in terminal]
    [Ctrl+D to end input]