Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git cannot lock ref 'HEAD': unable to resolve reference HEAD

I'm trying to commit the changes to my repository but I receive the error below:

git -c diff.mnemonicprefix=false -c core.quotepath=false commit -q -F C:\Users\Contronym\AppData\Local\Temp\bkdweixb.mnu
fatal: cannot lock ref 'HEAD': unable to resolve reference HEAD: Invalid argument

Completed with errors, see above.

I'm using bitbucket and SourceTree.

What's the reason for this commit failing? I was able to commit just fine the last 3 commits over the past week. Then, all of a sudden, I receive this error.

EDIT

I ran git gc and these are the results:

$ git gc
error: bad ref for HEAD
error: bad ref for HEAD
error: inflate: data stream error (unknown compression method)
fatal: loose object 53b65bd9b4fec7f6a7b0b3313c68199a18804327 (stored in .git/objects/53/b65bd9b4fec7f6a7b0b3313c68199a18804327) is corrupt
error: failed to run repack

I checked the directory .git/objects/53/b65bd9b4fec7f6a7b0b3313c68199a18804327 but that doesn't exist. There's two other files there, but b65bd9b4fec7f6a7b0b3313c68199a18804327 doesn't exist.

like image 851
Jake Miller Avatar asked Aug 20 '16 19:08

Jake Miller


3 Answers

I had the same problem and the only solution that I found was to navigate to the head like so:

.git/refs/heads/branch_name 

And I deleted the head file. Then I went to the console and I used the command:

git reset

Then all the files were unstaged so add them and commit them afterwards.

like image 183
Vasilisfoo Avatar answered Oct 19 '22 12:10

Vasilisfoo


I had the same problem, this worked for me:

Step 1.

  • go to .git\logs\refs\heads and open the Document named as YOUR_BRANCH, now copy the ID numbers in front of your user name and email

Step 2.

  • go to .git\refs\heads and open the document named as YOUR_BRANCH delete the line and paste the ID in.
like image 32
Rafael Marques Avatar answered Oct 19 '22 12:10

Rafael Marques


  1. Navigate to directory .git/refs/heads/branch_name

  2. Delete the preferred branch name

  3. Open terminal(git bash or cmd for windows)

    git reset
    
  4. Commit the changes (if necessary)

  5. Run the following command for merging the remote repository branch

    git pull
    

    If it gives related to refusing to merge unrelated histories, run the following command in the terminal:

    git pull origin master --allow-unrelated-histories
    
like image 10
SHAH MD IMRAN HOSSAIN Avatar answered Oct 19 '22 11:10

SHAH MD IMRAN HOSSAIN