1

I am attempting to replay a git bisect from an edited log to undo a mistake I made.

I mistakenly marked one of the commits as good when it should have been bad (or vice versa). I ran:

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

Then I edited that file to remove all the lines from the mistakenly labeled commit and below.

I then ran:

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

I'm now getting the error:

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?'

What is going on? How do I fix it? (Why is there a '?' at the end of the revision?)

I'm using git version 2.26.2.windows.1 on Windows 10. I use PowerShell 7 as my shell.

chwarr
  • 6,777
  • 1
  • 30
  • 57

2 Answers2

1

git bisect replay in Git before version 2.27 is unable to handle CRLF delimited files. The best fix for this is to upgrade to Git 2.27+, which has a contribution of mine to fix this.

PowerShell's massaging of the output of git bisect log converted the originally LF-only output of git bisect log to CRLF. You can see where the errant CR is showing up: it's the '?' in the error message.

If you cannot upgrade your copy of Git, there are a number of ways to avoid this:

  • Convert the file from CRLF back to LF.
    • If you're using PowerShell 5+, ((Get-Content C:\temp\bisect.log ) -join "`n") + "`n" | Set-Content -NoNewline \temp\bisect-lf.log
  • Have your text editor save the file with LF during editing.
  • Use CMD instead of PowerShell. Then, git bisect log > c:\temp\bisect.log won't change the newlines.

Hat tip to mklement0's answer for the PowerShell conversion one-liner. See it for nitty-gritty details.

There's a proposal to add a -Delimiter argument to Set-Content. If that get implemented, such conversion will be simpler.

chwarr
  • 6,777
  • 1
  • 30
  • 57
1

Christopher Warrington's (chwarr, the OP) patch has been merged in Git 2.27 (Q2 2020): "git bisect replay" had trouble with input files when they used CRLF line ending, which has been corrected.

See commit 6c722cb (07 May 2020) by Christopher Warrington (chwarr).
(Merged by Junio C Hamano -- gitster -- in commit f9dbe28, 14 May 2020)

bisect: allow CRLF line endings in "git bisect replay" input

Signed-off-by: Christopher Warrington

We advertise that the bisect log can be corrected in your editor before being fed to "git bisect replay", but some editors may turn the line endings to CRLF.

Update the parser of the input lines so that the CR at the end of the line gets ignored.

Were anyone to intentionally be using terms/revs with embedded CRs, replaying such bisects will no longer work with this change. I suspect that this is incredibly rare.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250