git 提交时无法设置 refs/heads/master

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30809205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:06:50  来源:igfitidea点击:

Couldn't set refs/heads/master when commit

gitgit-commit

提问by zkytony

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:

我的 .git/config 文件如下所示:

[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

回答by Rahul Gupta

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

看来你已经丢失了你的HEAD,所以你必须重新创建它。你可以用这个来做到这一点。

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

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

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

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

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

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.

使用它来扫描无法访问的对象。它将根据类型将悬空对象写入.git/lost-found/commit/.git/lost-found/other/。如果对象是 blob,内容将写入文件,而不是其对象名称。

回答by penno

This may help others; I waited about a minute and simply retried the commit and ... it worked.

这可能会帮助其他人;我等了大约一分钟,然后简单地重试提交,然后......它奏效了。

回答by Amit Shah

In my case the issue was with permission on the GIT repository on serverfor the path refs/Heads/master.

在我的情况下,问题出在服务器上 GIT 存储库的路径权限上refs/Heads/master

After allowing my username for accessing the mentioned path, all worked well.

允许我的用户名访问上述路径后,一切正常。

回答by dmlogs

Check your .git folder for file HEAD.

检查您的 .git 文件夹中的文件 HEAD。

$ cat .git/HEAD
ref: refs/heads/master

If this does not exist, create it.

如果它不存在,请创建它。

$ echo "ref: refs/Heads/master" > .git/HEAD