Bug Report or Unexpected Feature when "git restore -m ." restores merge conflicted state of a file after a commit
- From
- Terry Bear <terrythebear746@gmail.com>
- Date
- Apr 30, 2025, 21:03 UTC
- Message-ID
- <CAJt5hUyLoNfEbQe4wpES8AZP5yimos+xjqU9B4PszGxMrg50jg@mail.gmail.com>
What did you do before the bug happened? (Steps to reproduce your issue)
Can be replicated on a new repository.
1. Initialize git repo.
git init
2. Create a file
touch test-file
3. Write to the file
"update 1"
4. Stage the changes to the file, create a commit.
git add .
git commit -m "update 1"
5. Copy the branch
git branch -c "main-copy"
6. Write to the file on the same first "main" branch by appending new
content on the second line of the "test-file"
"update 2"
The file looks like:
"update 1"
"update 2"
7. Stage and commit.
git commit -a -m "update 2"
8. Introduce another change to the file but keep it on the work-space
by appending another line
"update 3"
The file looks like:
"update 1"
"update 2"
"update 3"
9. Make a merge switch
git switch --merge main-copy
The file on the "main-copy" branch should look like:
"update 1"
"<<<<<<< main-copy"
"======="
"update 2"
"update 3"
">>>>>>> local"
10. Stage and commit file
git commit -a -m "merge conflict on main-copy"
11. Restore merge-conflicted state
git restore -m .What did you expect to happen? (Expected behavior) The "git restore -m ." is not supposed to restore the merge-conflicted state of the file after it was staged and committed
What happened instead? (Actual behavior) The "git restore -m ." restored the merge-conflicted state of the file after it was staged and committed
What's different between what you expected and what actually happened? The restoration of the merge-conflicted state of the file after it was staged and committed
Anything else you want to add: I am not sure whether it is a bug or a feature but the behavior seemed unexpected and I couldn't find any mentions of it.
[System Info] git version: git version 2.34.1 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 6.8.0-57-generic #59~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Mar 19 17:07:41 UTC 2 x86_64 compiler info: gnuc: 11.4 libc info: glibc: 2.35 $SHELL (typically, interactive shell): /bin/bash
[Enabled Hooks] not run from a git repository - no hooks to show