Git 致命:参考格式无效:'refs/heads/master

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12773488/
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-10 14:44:14  来源:igfitidea点击:

Git fatal: Reference has invalid format: 'refs/heads/master

gitdropbox

提问by Justin

I am using Dropboxto sync a gitrepository, but now when I try and pushI am getting an error:

我正在使用Dropbox同步git存储库,但是现在当我尝试push时出现错误:

fatal: Reference has invalid format: 'refs/heads/master (MacBook-Pro's conflicted copy 2012-10-07)'

So, it seems that Dropbox detected a conflict and created a copy. Ok, no problem, so I deleted the conflicted file. Still, getting the above git error though.

因此,Dropbox 似乎检测到了冲突并创建了一个副本。好的,没问题,所以我删除了冲突的文件。尽管如此,还是出现了上述 git 错误。

$ git checkout master
    M   index.html
    Already on 'master'
$ git add .
$ git commit -a -m "Cleanup repo"
    [master ff6f817] Cleanup repo
    1 file changed, 5 insertions(+), 5 deletions(-)
$ git push
    fatal: Reference has invalid format: 'refs/heads/master (MacBook-Pro's conflicted copy 2012-10-07)'
    The remote end hung up unexpectedly`

How can I fix this? Thanks.

我怎样才能解决这个问题?谢谢。

回答by Lane

make a backup of your repo if you aren't sure about this one, because these commands are irreversible.

如果您不确定这个,请备份您的 repo,因为这些命令是不可逆的。

first, go to your repo directory.

首先,转到您的 repo 目录。

cd myrepo

then recursively search for the conflicted files and delete them

然后递归搜索冲突的文件并删除它们

find . -type f -name "* conflicted copy*" -exec rm -f {} \;

lastly, remove any "conflicted" references from git's packed-refs file

最后,从 git 的打包引用文件中删除任何“冲突”引用

awk '!/conflicted/' .git/packed-refs > temp && mv temp .git/packed-refs

回答by Marco Leogrande

The conflicted file could be in multiple places, I would look into:

冲突的文件可能在多个地方,我会调查:

.git/logs/refs/remotes/origin/
.git/logs/refs/heads/
.git/refs/remotes/origin/
.git/refs/heads/

Or you might look everywhere in the .gitsubdirectory: find . -name '*conflicted*'

或者您可能会在.git子目录中查看任何地方:find . -name '*conflicted*'

Or, otherwise, list the active branches with git branch -aand delete (git branch -d) anything suspicious.

或者,否则,列出活动分支git branch -a并删除 ( git branch -d) 任何可疑内容。

回答by Hareen Laks

This also happen to our team when my colleague push his changes and shutdown the PC before Dropbox get updated.

当我的同事在 Dropbox 更新之前推送他的更改并关闭 PC 时,我们的团队也会发生这种情况。

I solved it so simply.

我就这么简单地解决了。

Just deleted the conflicted copy. (XXXX's conflicted copy yyyy-mm-dd)

刚刚删除了冲突的副本。(XXXX 的冲突副本 yyyy-mm-dd)

And pull it normally.

并正常拉动。

Note that my colleague had the changes before messed up. And he push his changes again. This time no shutdown. :)

请注意,我的同事在搞砸之前进行了更改。他再次推动他的变化。这次没有关机。:)

回答by Drew

I was able to delete all the conflicted files from my .git folder, but I continued to get errors about files that no longer existed.

我能够从我的 .git 文件夹中删除所有冲突的文件,但我继续收到关于不再存在的文件的错误。

The fix for me was opening up .git/refs/packed_refsand deleting lines that contained the text "conflicted".

对我来说,修复是打开.git/refs/packed_refs并删除包含“冲突”文本的行。

回答by Rajesh Paul

For me it was giving error: fatal: Reference has invalid format: 'refs/tags/r0.2:3'

对我来说,它给出了错误: fatal: Reference has invalid format: 'refs/tags/r0.2:3'

You can go to /.git/packed_refsfile and delete the line for refs/tags/r0.2:3

您可以转到/.git/packed_refs文件并删除该行refs/tags/r0.2:3

Then it started working. But why it happened in the first place I don't know.

然后它开始工作。但为什么它首先发生我不知道。

回答by Sithu

I encounterd the similar error such as

我遇到了类似的错误,例如

fatal: Reference has invalid format: 'refs/heads/user-search-api (Sithu's conflicted copy 2016-01-08)'

Simply deletion of the file .git/refs/heads/user-search-api (Sithu's conflicted copy 2016-01-08)in the remote Dropbox repository did solve the problem.

只需删除.git/refs/heads/user-search-api (Sithu's conflicted copy 2016-01-08)远程 Dropbox 存储库中的文件即可解决问题。

回答by zeeawan

I was getting same error

我遇到了同样的错误

fatal: Reference has invalid format: 'refs/heads/somebranch (1)'

致命:引用格式无效:'refs/heads/somebranch (1)'

for the following command

对于以下命令

git branch

Then, I searched for erroneous name (branch name followed by (1) ) using the command

然后,我使用命令搜索了错误的名称(分支名称后跟 (1) )

find . -name 'somebranch (1)'

And it showed the following result

它显示了以下结果

./.git/refs/heads/somebranch (1)

./.git/refs/heads/somebranch (1)

Which is some duplicated version of somebranchIMO. So, I removed this by executing the find command following by delete

这是somebranchIMO 的一些重复版本。所以,我通过执行 find 命令删除了它,然后删除

find . -name 'somebranch (1)' -print -exec rm -rf {} \;

Then the branch command run successfully

然后分支命令运行成功

git branch

回答by poke

Try a git checkout masterfirst to get on the healthy, well-named branch.

git checkout master首先尝试进入健康、知名的分支。