git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git restore --staged -p on merge conflict causes crash

From
KHKristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
Date
Jan 7, 2025, 15:34 UTC
Message-ID
<27ec479b-b116-4fa7-b87c-416a5f7f3b25@app.fastmail.com>
In-Reply-To
<DM8PR02MB7942969BE7FEAFB48D9AEDCEC7112@DM8PR02MB7942.namprd02.prod.outlook.com>
On Tue, Jan 7, 2025, at 15:41, Keith Mendoza wrote:
Show 22 quoted lines
> What did you do before the bug happened? (Steps to reproduce your issue)
> 1. Start with a main branch
> 1. Add a new file (test.yaml)
> 1. git checkout --no-track -b branch-1
> 1. Commit a change to test.yaml
> 1. git checkout main
> 1. Commit a change to the same lines in test.yaml that was updated in branch-1
> 1. git checkout branch-1
> 1. git merge main
> 1. git restore --staged -p test.yaml
>
> What did you expect to happen? (Expected behavior)
> Be able to select which updates to restore
>
> What happened instead? (Actual behavior)
> The following is displayed on the console
> ```
> BUG: add-patch.c:497: diff starts with unexpected line:
> * Unmerged path test.yaml
>
> Aborted (core dumped)
> ```

It looks[1] like this was fixed in 28d1122f9ca (add-patch: handle "* Unmerged path" lines, 2023-03-09).[2] That fix was included in v2.41.0 and later. So not on your maintenance release (v2.39.5).

The bug was introduced in 2.37.0:
Jeff King wrote:
> Thanks, a fix is below. While the escape-hatch of the perl version is
> going away in v2.40, people have been exposed to the bug since we
> flipped the default in v2.37.0.
At least I wasn’t able to reproduce on 2.48.0.rc2 with the below.

``` git init && touch test.yaml && git add test.yaml && git commit -minit && git checkout --no-track -b branch-1 && echo something >test.yaml && git add test.yaml && git commit -mchange && git checkout main && echo 'something else (conflict)' >test.yaml && git add test.yaml && git commit -m'change here too' && git checkout branch-1 && # Merge conflict git merge main git restore --staged -p test.yaml ```

† 1: Based on:
      BUG: add-patch.c:498: diff starts with unexpected line:
🔗 2: https://lore.kernel.org/git/ZAmfqC9WMl3XeyEr@coredump.intra.peff.net/
Previous: Keith MendozaNext: Keith Mendoza
Message 2 of 3 in “git restore --staged -p on merge conflict causes crash”
  1. Keith MendozaJan 7, 2025
  2. Kristoffer HaugsbakkJan 7, 2025
  3. Keith MendozaJan 7, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.