Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

github - 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:UsersContronymAppDataLocalTempkdweixb.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...