如何反向应用有冲突的存储?

How to reverse apply a stash that with conflict?

我看到了问题How to reverse apply a stash? asked by Pat Notz。我已经尝试了批准的答案,但是我得到了这样的错误,

sudo git stash show -p | git apply --reverse
    error: patch failed: app/controllers/CloudController.php:673
    error: app/controllers/CloudController.php: patch does not apply
    error: patch failed: app/controllers/CloudGcode.php:1
    error: app/controllers/CloudGcode.php: patch does not apply

我必须解释一下我是如何 运行 遇到这种情况的。 我的存储列表中有一个存储,并且在我的工作存储库中进行了一些修改。我的工作存储库中的更改与 stash@{0} 有冲突。然后我错误地执行了git add .sudo git stash apply命令,它显示了这个信息,

sudo git stash apply
[sudo] password for xxxx:
    Auto-merging app/controllers/CloudGcode.php
    CONFLICT (add/add): Merge conflict in app/controllers/CloudGcode.php
    Auto-merging app/controllers/CloudController.php
    CONFLICT (content): Merge conflict in app/controllers/CloudController.php

应用隐藏后,我的文件中有这样的冲突,

<<<<<<< Updated upstream
            for($i = 0; $i < $textlen; $i++)
            {
                $char = $uchars[$index++];
                if($char !== 0)
                    $text = $text.chr($char);
            }
            $this->text = $text;
Log::info('LLLLLLLLLLLLLLLLLLLL'.$text);
=======
            for($i = 0; $i < $this->textlen; $i++)
                $text = $text.$uchars[$index++];
            $this->text = $text;
            $this->text[$this->textlen] = 0; // Terminate string overwriting checksum
>>>>>>> Stashed changes
            $this->waitUntilAllCommandsAreParsed = true; // Don't destroy string until executed
        }
        $this->formatErrors = 0;
        return true;
    }
<<<<<<< Updated upstream
=======

然后我google如何还原它。我进入问题 How to reverse apply a stash? asked by Pat Notz,并尝试了该问题的解决方案。 我想知道有没有办法在执行 sudo git stash apply 之前回滚状态,就在执行 git add .

之后或之前

你应该简单地重新存储,然后 git 重置(或者甚至 git reset --hard,前提是你先存储了),如“Aborting git stash apply”中所述。

如果您在没有先存储的情况下执行 reset --hard,您仍然可以在 .git/refs/stash 中看到您的补丁,如“Undo git reset --hard after git stash pop" (by a git stash apply would not remove the patch from the stash anyway, like git stash pop does, so here you don't have to worry about that), or you can recover it from git fsck.

中所述

I want to roll back the state before execute the sudo git stash apply

由于git apply --reverse不起作用,最好按照我上面的建议回到HEAD,重新操作。