Skip to content

merge-file --object-id aborts with "cannot reinitialize an already-initialized object directory" in a linked worktree #6350

Description

@LewisADay

Existing issues matching what you're seeing

  • I was not able to find an open or closed issue matching what I'm seeing

Git for Windows version

git version 2.53.0.windows.1
cpu: x86_64
built from commit: a5512bdee37ed7142c233d21e2d347ffc4860ff3
sizeof-long: 4
sizeof-size_t: 8
shell-path: D:/git-sdk-64-build-installers/usr/bin/sh
rust: disabled
feature: fsmonitor--daemon
gettext: enabled
libcurl: 8.18.0
OpenSSL: OpenSSL 3.5.5 27 Jan 2026
zlib: 1.3.1
SHA-1: SHA1_DC
SHA-256: SHA256_BLK
default-ref-format: files
default-hash: sha1

Windows version

Windows 11

Windows CPU architecture

x86_64 (64-bit)

Additional Windows version information

Microsoft Windows [Version 10.0.26200.8390]

Options set during installation

Editor Option: VisualStudioCode
Custom Editor Path:
Default Branch Option: main
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: WinSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Git Pull Behaviour Option: Merge
Use Credential Manager: Enabled
Performance Tweaks FSCache: Enabled
Enable Symlinks: Disabled
Enable FSMonitor: Disabled

Other interesting things

  • Three copies of the same OID are used only to minimise the reproducer.
    The bug fires equally with three distinct OIDs which was the discovery vector.

  • The failure is independent of blob content, argument order, and the
    --ours/--theirs/--union/--stdout flags.

  • Running the very same command from ../bug-repro (the main worktree)
    with the same OID exits 0.

  • For reference, the Trace2 output from the failing invocation looks a little something like this:

common-init.c:57  version 2.53.0.windows.1
common-init.c:58  start get.exe merge-file --stdout --object-id <oid> <oid> <oid>
repository.c:237  worktree <path-to-worktree>
git.c:503  cmd_name merge-file (merge-file)
usage.c:346  error cannot reinitialize and already-initialized object directory
  • I have replicated this on two machines on version 2.53.0.windows.1, and yet I've been unable to trigger it on one running version 2.47.1.windows.2. For the sake of completeness I include that working installation's system info and install options below

git version 2.47.1.windows.2
cpu: x86_64
built from commit: 36a139e
sizeof-long: 4
sizeof-size_t: 8
shell-path: D:/git-sdk-64/usr/bin/sh
feature: fsmonitor--daemon
libcurl: 8.11.0
OpenSSL: OpenSSL 3.2.3 3 Sep 2024
zlib: 1.3.1
uname: Windows 10.0 26200
compiler info: gnuc: 14.2
libc info: no libc information available
$SHELL (typically, interactive shell):

Editor Option: VisualStudioCode
Custom Editor Path:
Default Branch Option:
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Git Pull Behavior Option: Merge
Use Credential Manager: Enabled
Performance Tweaks FSCache: Enabled
Enable Symlinks: Disabled
Enable FSMonitor: Disabled

Terminal/shell

PowerShell

Commands that trigger the issue

mkdir bug-repo
cd bug-repo
git init -b main
echo hello > file.txt
git add file.txt
git commit -m init --quiet
git worktree add ../linked --quiet
cd ../linked
$oid=$(git rev-parse HEAD:file.txt)
git merge-file --stdout --object-id "$oid" "$oid" "$oid"

Expected behaviour

Exit code 0, with the blob content written to stdout. (A successful merge)

Actual behaviour

Exit code 3, and output:

BUG: repository.c:171: cannot reinitialize an already-initialized object directory

Repository

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions