我是错误 : “error: while searching for:”

标签 git patch git-am

运行 git am 我得到上面的错误。手动比较我没有看到任何问题。有人可以指出错误在哪里吗?

$ git am 0012-Do-not-die-when-something-nasty-happen-in-the-comman.patch --reject
Applying: Do not die when something nasty happen in the command
Checking patch lib/Devel/DebugHooks/CmdProcessor.pm...
error: while searching for:
    return 0   unless  $cmd  &&  exists $DB::commands->{ $cmd };

    # The command also should return defined value to keep interaction
    if( defined (my $result =  $DB::commands->{ $cmd }( $args_str )) ) {
        return $result   unless ref $result;

        # Allow commands to evaluate $expr at a debugged script context

error: patch failed: lib/Devel/DebugHooks/CmdProcessor.pm:14
Applying patch lib/Devel/DebugHooks/CmdProcessor.pm with 1 reject...
Rejected hunk #1.
Patch failed at 0001 Do not die when something nasty happen in the command
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

.rej:

$ cat CmdProcessor.pm.rej 
diff a/lib/Devel/DebugHooks/CmdProcessor.pm b/lib/Devel/DebugHooks/CmdProcessor.pm  (rejected hunks)
@@ -14,7 +14,10 @@ sub process {
    return 0   unless  $cmd  &&  exists $DB::commands->{ $cmd };

    # The command also should return defined value to keep interaction
-   if( defined (my $result =  $DB::commands->{ $cmd }( $args_str )) ) {
+   my $result =  eval { $DB::commands->{ $cmd }( $args_str ) };
+   do{ print $DB::OUT "'$cmd' command died: $@"; return 1; }   if $@;
+
+   if( defined $result ) {
        return $result   unless ref $result;

        # Allow commands to evaluate $expr at a debugged script context

来源:

$ cat CmdProcessor.pm 
package Devel::DebugHooks::CmdProcessor;

sub process {
    my( $dbg ) =  shift;

    my( $cmd, $args_str ) =  shift =~ m/^([\w.]+)(?:\s+(.*))?$/;
    $args_str //=  '';


    return 0   unless  $cmd and exists $DB::commands->{ $cmd };

    # The command also should return defined value to keep interaction
    if( defined (my $result =  $DB::commands->{ $cmd }( $args_str )) ) {
        return $result   unless ref $result;

        # Allow commands to evaluate $expr at a debugged script context
        if( ref( $result ) eq 'HASH' ) {
            return $result->{ code }->(
                $args_str
                ,DB::eval( $result->{ expr } ) # FIX: it is not evaled at script context
            );
        }

        return $result;
    }
    else {
        return;
    }


    return 0;
}

1;

行尾是 unix。

尝试手动运行 git apply 会出现下一个错误:

$ git apply CmdProcessor.pm.rej 
fatal: patch fragment without header at line 2: @@ -14,7 +14,10 @@ sub process {

最佳答案

git 正在搜索行

return 0 unless $cmd && exists $DB::commands->{ $cmd };

但是你的代码包含这一行

return 0 unless $cmd and exists $DB::commands->{ $cmd };

(我标记了 &&and 之间的区别)补丁不适用。

您可以找到有关 git 冲突解决的不错教程 here .

关于我是错误 : “error: while searching for:” ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34870627/

相关文章:

git am 应该忽略以 "[]"开头的提交消息中的某些内容吗?

git - 失败的补丁更改了我的 Git Bash 提示,我该如何恢复它?

git - git cherry-pick 和 git format-patch 有什么区别?我是 SCSS ?

git - git add --intent-to-add 或 -N 的作用是什么,应该在什么时候使用?

git - GPL 许可的版本控制(例如 Git)

arrays - 戈朗 : calculate diff between two array of bytes and patch an array

git - Magento 的 SUPEE-6788 补丁不适用于 Git/Github

git - 一次提交上的多个构建

linux - ZSH 中的管道从 Git 日志输出中剥离颜色

git - 使用 Intellij 创建 git 修订补丁