git 错误:无法锁定 ref.. 'refs/tags' 存在;无法创建 'refs/tags/
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43533473/
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
error: cannot lock ref.. 'refs/tags' exists; cannot create 'refs/tags/
提问by k3it
I'm getting a strange "cannot lock ref" error when trying to pull changes from github. I've tried git gc, and looked around for similar errors but can't find a solution.
尝试从 github 中提取更改时,我收到一个奇怪的“无法锁定引用”错误。我试过 git gc,并环顾四周寻找类似的错误,但找不到解决方案。
> git pull
error: cannot lock ref 'refs/tags/v2.8': 'refs/tags' exists; cannot create 'refs/tags/v2.8'
From github.com:k3it/qsorder
! [new tag] v2.8 -> v2.8 (unable to update local ref)
error: cannot lock ref 'refs/tags/v2.9': 'refs/tags' exists; cannot create 'refs/tags/v2.9'
! [new tag] v2.9 -> v2.9 (unable to update local ref)
回答by torek
Your Git is complaining that a reference (rather than a directory) named refs/tags
exists. It's not clear what would createthat, but see if git rev-parse refs/tags
produces a hash ID. If so, that reference needs to go away:
您的 Git 抱怨refs/tags
存在一个名为的引用(而不是目录)。不清楚是什么会创建它,但看看是否git rev-parse refs/tags
会产生一个哈希 ID。如果是这样,该引用需要消失:
git update-ref -d refs/tags
after which git fetch
should work.
之后git fetch
应该工作。
If git rev-parse refs/tags
fails (which it should—refs/tags
itself should not be a valid name) then this is notthe problem and it's not clear what the actual problem is.
如果git rev-parse refs/tags
失败(它应该——refs/tags
它本身不应该是一个有效的名称)那么这不是问题,也不清楚实际问题是什么。
回答by Xstatic
Running
跑步
git remote prune origin
Worked for me. Not sure why this was the issue, but seems like there was a broken reference to a remote branch.
对我来说有效。不知道为什么会出现这个问题,但似乎对远程分支的引用已损坏。
回答by Sajib Khan
error: cannot lock ref 'refs/tags/v2.8': 'refs/tags' exists; cannot create 'refs/tags/v2.8' From github.com:k3it/qsorder
错误:无法锁定引用“refs/tags/v2.8”:“refs/tags”存在;无法从 github.com:k3it/qsorder 创建“refs/tags/v2.8”
Try deleting your local tag v2.8
and v2.9
then pull again.
尝试删除您的本地标签v2.8
,v2.9
然后再次拉取。
$ git tag -d v2.8
$ git tag -d v2.9
$ git pull
If you want to delete all local tags by a command:
如果要通过命令删除所有本地标签:
$ git tag | xargs git tag -d
回答by Tomer Bar-Shlomo
#!/usr/bin/env bash
echo "update-ref delete refs/tags"
log="git-update-ref-errors.log"
script="./git-update-ref-exist-tags-delete.sh"
git_command="git update-ref -d refs/tags"
echo "log errors from ${git_command} to ${log}"
${git_command} 2>&1 | > ${log}
echo "show errors to ${log}"
cat ${log}
echo create ${script}
touch ${script}
echo "add execute (+x) permissions to ${script}"
chmod +x ${script}
echo "generate ${script} from errors log ${log}"
${git_command} 2>&1 | grep 'exists' | sed -n "s:.*\: 'refs/tags/\(.*\)' exists;.*:git tag -d '':p" >> ${script}
echo "execute ${script}"
${script}
echo fetch
log="git-fetch-errors.log"
script="./git-fetch-exist-tags-delete.sh"
git_command="git fetch"
echo "log errors from ${git_command} to ${log}"
${git_command} 2>&1 | > ${log}
echo "show errors from ${log}"
cat ${log}
echo create ${script}
touch ${script}
echo "add execute (+x) permissions to ${script}"
chmod +x ${script}
echo "generate ${script} from errors log ${log}"
${git_command} 2>&1 | grep 'exists' | sed -n "s:.*\: 'refs/tags/\(.*\)' exists;.*:git tag -d '':p" >> ${script}
echo "execute ${script}"
${script}
git fetch
echo pull
log="git-pull-errors.log"
script="./git-pull-exist-tags-delete.sh"
git_command="git pull"
echo "log errors from ${git_command} to ${log}"
${git_command} 2>&1 | > ${log}
echo "show errors from ${log}"
cat ${log}
echo create ${script}
touch ${script}
echo "add execute (+x) permissions to ${script}"
chmod +x ${script}
echo "generate ${script} from errors log ${log}"
${git_command} 2>&1 | grep 'exists' | sed -n "s:.*\: 'refs/tags/\(.*\)' exists;.*:git tag -d '':p" >> ${script}
echo "execute ${script}"
${script}
git pull
The script above will log errors to XXX-errors.log and fix them by generating and running a XXX-exist-tags-delete.sh automatically from the XXX-errors.log using the following commands:
上面的脚本将错误记录到 XXX-errors.log 并通过使用以下命令从 XXX-errors.log 自动生成和运行 XXX-exist-tags-delete.sh 来修复它们:
- git update-ref -d refs/tags
- git fetch
- git pull
- git update-ref -d 参考/标签
- 混帐
- 拉
回答by Melad
I was trying to push (/dev/somechanges) and I have a remote branch (/dev) with the same prefix when I choose a new name that is not starting with /dev it worked fine.
我试图推送 (/dev/somechanges) 并且当我选择一个不以 /dev 开头的新名称时,我有一个具有相同前缀的远程分支 (/dev) 它工作正常。
回答by Shane Fast
For a quick work around you can use
为了快速解决您可以使用
git push --delete origin 'v2.8'
git push --delete origin 'v2.8'
git push --delete origin 'v2.9'
git push --delete origin 'v2.9'
回答by Krishna Jit
This is what I tried and it worked for me.
这是我尝试过的,它对我有用。
git remote prune origin