Viewed
Viewed

Reputation: 1413

Visual Studio does not see the local repository. Fatal: cannot lock ref 'HEAD'

I had a local repository in my Visual Studio project. Made a commit. A little later, the electricity was cut off. Now I open the project, there is no repository. At the same time, it remained in the project folder. How to return it to Visual Studio?

enter image description here enter image description here

I can't crate new branch. When I tried commit all changes I took error

fatal: cannot lock ref 'HEAD': unable to resolve reference 'refs/heads/master': reference broken

Upvotes: 0

Views: 424

Answers (2)

torek
torek

Reputation: 488003

Obviously your own answer solved your problem here.

The other thing that commonly happens when the power goes off suddenly (or the host crashes) is that the special file HEAD (.git/HEAD) gets wiped out or corrupted.

Git stores branch information in several places:

  • The special file HEAD usually contains the name of the current branch.

    Inspecting .git/HEAD, you'll see, e.g., the text ref: refs/heads/master if you have done git checkout master, or ref: refs/heads/feature if you have done git checkout feature.

    This file is how Git knows which branch you're on. This file gets updated pretty frequently.

  • Files named .git/refs/heads/master, .git/refs/heads/feature, and so on often contain the correct hash ID for each of these branches.

    When you make a new commit, such a file is either created or rewritten in place to hold the hash ID of the new commit. When you use commands that update a branch name, these files get created or updated.

  • A file named .git/packed-refs often contains hash IDs for every branch and tag name, or some subset of them. These are the correct hash IDs if they're not superseded by some other information. This file is written much more rarely.

When the power fails, or the computer crashes, the most-recently-updated files are the ones most likely to become corrupt (because the computer itself and/or the storage medium delay the actual data-writing so as to batch things together for efficiency). So .git/HEAD and .git/refs/heads/name are among the files that are likely to be damaged in these events.

Note that other files, in .git/objects, may also be damaged. You can check for this using git fsck. However, git fsck prints informational messages about normal conditions too, so don't be too alarmed if you get various messages about "dangling" commits, tags, trees, and blobs, or the occasional "warning" message like this one:

warning in tag d6602ec5194c87b0fc87103ca4d67251c76f233a: missingTaggerEntry: invalid format - expected 'tagger' line

Upvotes: 1

Viewed
Viewed

Reputation: 1413

I went to file \.git\logs\refs\heads\master and took then last ref

enter image description here

Then went to \.git\refs\heads\master and replaced the ref

enter image description here

And now Visual Studio the see all commit

enter image description here

Upvotes: 2

Related Questions