【问题标题】:Cannot replay git bisect: "error: couldn't get the oid of the rev"无法重播 git bisect:“错误:无法获得 rev 的 oid”
【发布时间】:2025-12-24 14:05:12
【问题描述】:

我正在尝试将已编辑日志中的 git bisect 重播到我创建的 undo a mistake

我错误地将其中一个提交标记为好,而它本应该是坏的(反之亦然)。我跑了:

git bisect log > C:\temp\bisect.log
# Alternatively
git bisect log | Set-Content -Encoding ASCII C:\temp\bisect.log

然后我编辑了该文件以从错误标记的提交中删除所有行。

然后我跑了:

git bisect reset
git bisect replay c:\temp\bisect.log

我现在收到错误:

We are not bisecting.
Bisecting: 5211 revisions left to test after this (roughly 12 steps)
[9bc79b2f25a3724376d7af19617c33749a30ea3a] Merge branch 'release/2.1' into release/2.2
error: couldn't get the oid of the rev '9bc79b2f25a3724376d7af19617c33749a30ea3a?'

发生了什么事?我如何解决它? (为什么修订的末尾有一个“?”?)

我在 Windows 10 上使用 git 版本 2.26.2.windows.1。我使用 PowerShell 7 作为我的 shell。

【问题讨论】:

    标签: git powershell newline git-bisect


    【解决方案1】:

    Christopher Warrington(chwarr,OP)补丁已合并到 Git 2.27(2020 年第二季度):“git bisect replay”在使用 CRLF 行结尾时遇到输入文件问题,已更正。

    参见 Christopher Warrington (chwarr)commit 6c722cb(2020 年 5 月 7 日)。
    (由 Junio C Hamano -- gitster -- 合并到 commit f9dbe28,2020 年 5 月 14 日)

    bisect:在“git bisect replay”输入中允许 CRLF 行结尾

    签字人:Christopher Warrington

    我们宣传可以在您的编辑器中更正对分日志,然后再将其输入“git bisect replay”,但有些编辑器可能会将行尾转换为 CRLF。

    更新输入行的解析器,以便忽略行尾的 CR。

    如果有人故意在嵌入式 CR 中使用术语/版本,那么重播此类对分将不再适用于此更改。我怀疑这非常罕见。

    【讨论】:

      【解决方案2】:

      git bisect replay 在 2.27 版之前的 Git 中无法处理 CRLF 分隔文件。最好的解决办法是升级到 Git 2.27+,它有 a contribution of mine to fix this

      PowerShell 对git bisect log 输出的按摩将git bisect log 的最初仅LF 输出转换为CRLF。您可以看到错误的 CR 出现在哪里:它是“?”在错误消息中。

      如果您无法升级您的 Git 副本,有多种方法可以避免这种情况:

      • 将文件从 CRLF 转换回 LF。
        • 如果您使用 PowerShell 5+,((Get-Content C:\temp\bisect.log ) -join "`n") + "`n" | Set-Content -NoNewline \temp\bisect-lf.log
      • 让您的文本编辑器在编辑期间使用 LF 保存文件。
      • 使用 CMD 而不是 PowerShell。然后,git bisect log > c:\temp\bisect.log 不会更改换行符。

      mklement0answer 致敬,用于PowerShell 转换单行。请参阅它以获取详细信息。

      有一个proposal 可以将-Delimiter 参数添加到Set-Content。如果实现了,这样的转换会更简单。

      【讨论】: