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

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

From
KMKeith Mendoza <kmendoza@beyondtrust.com>
Date
Jan 7, 2025, 14:41 UTC
Message-ID
<DM8PR02MB7942969BE7FEAFB48D9AEDCEC7112@DM8PR02MB7942.namprd02.prod.outlook.com>
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) ```

What's different between what you expected and what actually happened? git crashed and generated a core dump.

Anything else you want to add: Here's the output of git diff after the `git merge main`

``` diff --cc test.yaml index 26bf81a,46282a7..0000000

--- a/test.yaml
+++ b/test.yaml
@@@ -1,7 -1,7 +1,13 @@@
  job:
++<<<<<<< HEAD
 +  newfield:
 +    field1: blah
 +    field2: blah-blah
++=======
+   conflict-field:
+     blah1: blah-blah
+     blah2: blah-blah-blah
++>>>>>>> main
    something:
      required: true
      other: 1
```

The generated core dump is attached.

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.39.5
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64
compiler info: gnuc: 12.2
libc info: glibc: 2.36
$SHELL (typically, interactive shell): /bin/bash


[Enabled Hooks]
Next: Kristoffer Haugsbakk
Message 1 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.