Skip to content

"Repository has no commit" error in case of worktree + packed-refs #1290

Closed

Description

@vikukush

After git decided to pack my repo with several worktrees and a bunch of local branches, my builds started failing with following error:

D:\Corextroot\microsoft.build.tasks.git\8.0.0\build\Microsoft.Build.Tasks.Git.targets(25,5): Repository has no commit. [D:\Pl3\Test\UnitTests\Common\Tools.UnitTests.Common\Tools.UT.Common.csproj]

  • D:\Pl3 is a worktree of D:\Platform.
  • D:\Platform\.git\worktrees\Pl3\refs is empty.
  • D:\Platform\.git\refs\heads doesn't have a ref of a branch that's checked out in D:\Pl3 either
  • The only reference to the commit ID of a branch specified in D:\Platform\.git\worktrees\Pl3\HEAD is in D:\Platform\.git\packed-refs

Sourcelink task is unable to handle this situation.

I have worked to add a unit test that covers my scenario: #1289

Activity

  1. vikukush commented on Oct 2, 2024

    @vikukush
    Author

    The issue went away after I created the very next commit, which created D:\Platform.git\refs\heads\user\vikukush\mstestv3 file, so the commit ID was no longer inside packed-refs.
    So the bug can be easily worked around, but this of course still needs to be fixed.

  2. bradwilson commented on Mar 13, 2026

    @bradwilson

    I just started using git worktree and ran into this.

    Any progress here, or even an acknowledgment from the team that it's an issue to be fixed?

  3. tmat commented on Mar 13, 2026

    @tmat
    Member

    Will take a look.

  4. tmat commented on Apr 21, 2026

    @tmat
    Member

    The path D:\Corextroot\microsoft.build.tasks.git\8.0.0 indicates that you're using .NET SDK 8.0. Does the issue reproduce with .NET SDK 10?

  5. jjonescz commented on Apr 21, 2026

    @jjonescz
    Member

    I'm hitting this too. I'm using Microsoft.Build.Tasks.Git from .NET SDK 10.0.105. It seems this happens when the HEAD ref is packed, i.e., there is no file under refs/heads/ for it in .git folder, it's only in .git/packed-refs. Can be worked around by creating a new commit (since that one won't be packed yet).

  6. tmat commented on Apr 21, 2026

    @tmat
    Member

    @jjonescz Do you have repro steps how do you get the repo to that state?

  7. jjonescz commented on Apr 21, 2026

    @jjonescz
    Member

    I can try to create a small repro if you want. But based on my analysis, if you use git pack-refs to make the current HEAD a packed ref, that should be it. It seems there is even a PR with a unit test for this (which seems correct at a high level to me): https://github.com/dotnet/sourcelink/pull/1289/changes

  8. tmat commented on Apr 21, 2026

    @tmat
    Member

    I tried to repro with out of our repos, using git pack-refs --all -- this removed refs/heads files but source link was still working (getting the commit sha from the packed refs).

  9. tmat commented on Apr 21, 2026

    @tmat
    Member
  10. added this to the 10.0.4xx milestone on Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions