简体   繁体   English

Git致命:引用的格式无效:'refs / heads / master

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

I am using Dropbox to sync a git repository, but now when I try and push I 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. 因此,似乎Dropbox检测到冲突并创建了副本。 Ok, no problem, so I deleted the conflicted file. 好的,没问题,所以我删除了冲突的文件。 Still, getting the above git error though. 尽管如此,仍然可以获得上述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. 谢谢。

make a backup of your repo if you aren't sure about this one, because these commands are irreversible. 如果您不确定这个,请备份您的仓库,因为这些命令是不可逆转的。

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的packed-refs文件中删除任何“冲突的”引用

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

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 .git subdirectory: find . -name '*conflicted*' 或者你可以在.git子目录中随处find . -name '*conflicted*'find . -name '*conflicted*' find . -name '*conflicted*'

Or, otherwise, list the active branches with git branch -a and delete ( git branch -d ) anything suspicious. 或者,否则,使用git branch -a列出活动分支,并删除( git branch -d )可疑的任何内容。

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. 这次没有关机。 :) :)

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_refs and deleting lines that contained the text "conflicted". 我的修复是打开.git/refs/packed_refs并删除包含“冲突”文本的行。

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_refs file 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. 但为什么它发生在我不知道的第一个地方。

首先尝试使用git checkout master来获得健康,命名良好的分支。

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 somebranch IMO. 这是某些分支 IMO的重复版本。 So, I removed this by executing the find command following by delete 所以,我通过执行delete命令后面的find命令删除了它

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

Then the branch command run successfully 然后branch命令成功运行

git branch

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. 只需在远程Dropbox存储库中删除文件.git/refs/heads/user-search-api (Sithu's conflicted copy 2016-01-08)就可以解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命:参考格式无效:'refs / heads / master~' - fatal: Reference has invalid format: 'refs/heads/master~' Git:引用格式无效:“ refs / heads / SomeBranch” - Git: Reference has invalid format: 'refs/heads/SomeBranch' Git 致命:坏 object refs/heads 2/master - Git fatal: bad object refs/heads 2/master GitHub App & Heroku — 致命:引用格式无效:“refs/remotes/heroku/master” - GitHub App & Heroku — fatal: Reference has invalid format: 'refs/remotes/heroku/master' GIT拉取-致命错误-引用格式无效:“ refs / tags /在字符串内部函数和内存gz之前” - GIT Pull - Fatal error - Reference has invalid format: 'refs/tags/before string intern functions and memory gz' 致命:参考格式无效:'refs / stash 2'(128) - fatal: Reference has invalid format: 'refs/stash 2' (128) 致命:refspec的远程部分不是.git / refs / heads / master中的有效名称:.git / refs / remotes / origin / master - fatal: remote part of refspec is not a valid name in .git/refs/heads/master:.git/refs/remotes/origin/master 无法提交Git更改。 错误消息:致命:无法锁定ref'HEAD':无法解析引用'refs / heads / master':引用破坏 - Unable to Commit Git Changes. Error Message: fatal: cannot lock ref 'HEAD': unable to resolve reference 'refs/heads/master': reference broken 致命的:无效的refspec'+ refs / heads / *' - fatal: Invalid refspec '+refs/heads/*' Git远程命令返回致命:无效的refspec + refs / heads / *:refs / remotes /:origin / * - Git remote command returns fatal: Invalid refspec +refs/heads/*:refs/remotes/:origin/*
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM