提交时无法设置参考/头/主 [英] Couldn't set refs/heads/master when commit

查看:244
本文介绍了提交时无法设置参考/头/主的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我昨天能够犯下罚款。但是今天(我没有改变任何东西),当我提交时:

  $ git add config.h 
$ git commit -m更新config.h重置值
错误:无法设置refs / heads / master
致命:无法更新HEAD ref

我知道这个错误也可能在拉或推过程中发生。但我还没有找到解决方案来解决它提交时。



我的.git / config文件看起来像这样:

  [core] 
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[remoteorigin]
url = git @ SOME_URL
fetch = + refs / heads / *:refs / remotes / origin / *
[branchmaster]
remote = origin
merge = refs / heads / master


解决方案

看来你已经失去了你的 HEAD ,所以你将不得不重新创建它。你可以这样做。

  echo ref:refs / heads / master> .git / HEAD 

这会在您的.git文件夹中创建一个 HEAD 文件。这应该可以解决你的问题。



另外,试试 git fsck 命令。它验证数据库中对象的连通性和有效性。

  git fsck --lost-found 

code>

使用它扫描不可达的对象。它会将悬挂对象写入 .git / lost-found / commit / .git / lost-found / other / ,取决于类型。如果对象是blob,则将内容写入文件中,而不是其对象名称。


I was able to commit fine yesterday. But today (I didn't change anything), when I commit:

$ git add config.h
$ git commit -m "Update config.h to reset the values"
error: Couldn't set refs/heads/master
fatal: cannot update HEAD ref

I know that this error may happen also during pull or push. But I haven't found a solution to fix it when committing.

My .git/config file looks like this:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[remote "origin"]
    url = git@SOME_URL
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

解决方案

It seems you have lost your HEAD, so you will have to recreate it. You can do that using this.

echo ref: refs/heads/master >.git/HEAD

This will create a HEAD file in your .git folder. That should solve your problem.

Also, try the git fsck command. It verifies the connectivity and validity of the objects in the database.

git fsck --lost-found

Use this to scan for unreachable objects. It will write dangling objects into .git/lost-found/commit/ or .git/lost-found/other/, depending on type. If the object is a blob, the contents are written into the file, rather than its object name.

这篇关于提交时无法设置参考/头/主的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆