threads / discuss / 57621

fast forward merge anomaly, 'commit' after 'reset --soft' can produce new commit with same hash as before

Subject: fast forward merge anomaly, 'commit' after 'reset --soft' can produce new commit with same hash as before

## tl;dr

One message between Mar 26, 2022 and Mar 26, 2022.

replies: 0people: 1as markdown or json

Maximilian Reichel· Mar 26, 2022, 14:23 UTC · lore

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue) Running the following script with and without the sleep command. ``` #!/bin/bash git -c init.defaultBranch=master init git config user.email "e@mail.com" git config user.name "Name" git commit -m init --allow-empty git checkout -b otherBranch git commit -a --allow-empty -m first git checkout master git merge --ff otherBranch git notes add -m foo # sleep 2 git reset --soft HEAD~1 git commit -a --allow-empty -m first git notes add -f -m bar git log --graph --abbrev-commit --decorate --all git checkout otherBranch git notes show ```

What did you expect to happen? (Expected behavior) I expected that the sleep command will not affect the behavior of the script.

What happened instead? (Actual behavior) Without the sleep command, the note attached to the HEAD of otherBranch contains the message "bar" (most of the time). With the sleep command, the note attached to the HEAD of otherBranch contains the message "foo".

What's different between what you expected and what actually happened? Without the sleep command, the last commit will have the same commit id as the HEAD before the reset. Because of this collision, we can not attach notes to HEAD of the master and the HEAD of otherBranch independently.

Anything else you want to add: I tested this on git 2.35.1, 2.30.2 and 2.21.0, and they are all affected. I attached the console output of the script with and without the sleep command to this mail.

[System Info] git version: git version 2.35.1 cpu: x86_64 built from commit: 4c53a8c20f8984adb226293a3ffd7b88c3f4ac1a sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 5.10.25-linuxkit #1 SMP Tue Mar 23 09:27:39 UTC 2021 x86_64 compiler info: gnuc: 10.2 libc info: glibc: 2.31 $SHELL (typically, interactive shell): <unset>

[Enabled Hooks] not run from a git repository - no hooks to show

warning: templates not found in /usr/local/share/git-core/templates
Initialized empty Git repository in /test/state.ff/.git/
[master (root-commit) c298c33] init
Switched to a new branch 'otherBranch'
[otherBranch ae621d9] first
Switched to branch 'master'
Updating c298c33..ae621d9
Fast-forward
[master 1681165] first
* commit 1681165 (HEAD -> master)
| Author: Name <e@mail.com>
| Date:   Sat Mar 26 13:35:57 2022 +0000
| 
|     first
| 
| Notes:
|     bar
|   
| * commit be3204c (refs/notes/commits)
| | Author: Name <e@mail.com>
| | Date:   Sat Mar 26 13:35:57 2022 +0000
| | 
| |     Notes added by 'git notes add'
| | 
| * commit aff6c5b
|   Author: Name <e@mail.com>
|   Date:   Sat Mar 26 13:35:55 2022 +0000
|   
|       Notes added by 'git notes add'
|   
| * commit ae621d9 (otherBranch)
|/  Author: Name <e@mail.com>
|   Date:   Sat Mar 26 13:35:55 2022 +0000
|   
|       first
|   
|   Notes:
|       foo
| 
* commit c298c33
  Author: Name <e@mail.com>
  Date:   Sat Mar 26 13:35:55 2022 +0000
  
      init
Switched to branch 'otherBranch'
foo
warning: templates not found in /usr/local/share/git-core/templates
Initialized empty Git repository in /test/state.ff/.git/
[master (root-commit) 2cd4638] init
Switched to a new branch 'otherBranch'
[otherBranch e803e0a] first
Switched to branch 'master'
Updating 2cd4638..e803e0a
Fast-forward
[master e803e0a] first
Overwriting existing notes for object e803e0a4625722bd00efc5ff39b0d70b55ecae30
* commit e803e0a (HEAD -> master, otherBranch)
| Author: Name <e@mail.com>
| Date:   Sat Mar 26 13:35:47 2022 +0000
| 
|     first
| 
| Notes:
|     bar
| 
* commit 2cd4638
  Author: Name <e@mail.com>
  Date:   Sat Mar 26 13:35:47 2022 +0000
  
      init
  
* commit 21e0b57 (refs/notes/commits)
| Author: Name <e@mail.com>
| Date:   Sat Mar 26 13:35:47 2022 +0000
| 
|     Notes added by 'git notes add'
| 
* commit a3da577
  Author: Name <e@mail.com>
  Date:   Sat Mar 26 13:35:47 2022 +0000
  
      Notes added by 'git notes add'
Switched to branch 'otherBranch'
bar

← back to recent threads