Git 报错:unable to update local ref
目录
问题
今天在一个老旧项目目录中同步代码时遇到了一个报错:unable to update local ref。
具体操作流程如下:
root@928c09c89c1c:/home/work/bag# git pullerror: cannot lock ref 'refs/remotes/origin/lozen/remux': 'refs/remotes/origin/lozen' exists; cannot create 'refs/remotes/origin/lozen/remux'From git.baijiashilian.com:LLL/gloud/bag ! [new branch] lozen/remux -> origin/lozen/remux (unable to update local ref)error: cannot lock ref 'refs/remotes/origin/lozen/tc': 'refs/remotes/origin/lozen' exists; cannot create 'refs/remotes/origin/lozen/tc' ! [new branch] lozen/tc -> origin/lozen/tc (unable to update local ref) * [new tag] 1.0.8.142-dasheng -> 1.0.8.142-dasheng * [new tag] 1.0.8.241 -> 1.0.8.241 * [new tag] 1.0.9.021 -> 1.0.9.021
执行完 git pull 命令之后,最新的分支都已经同步下来,但是有两个分支报错了,具体的报错信息就是 unable to update local ref。其实这是一种比较常见的 Git 的报错,今天遇到了,就拿出来介绍一下解决方法。
解决
就像把大象装冰箱,总共分三步。
步骤一、清除松散对象。
命令如下:
git gc --prune=now
执行过程如下:
root@928c09c89c1c:/home/work/bag# git gc --prune=nowEnumerating objects: 3534, done.Counting objects: 100% (3534/3534), done.Delta compression using up to 64 threadsCompressing objects: 100% (1211/1211), done.Writing objects: 100% (3534/3534), done.Total 3534 (delta 2306), reused 3450 (delta 2230)
步骤二、刷新本地分支
同步远程仓库分支到本地,删除远程分支不存在但是本地还有的分支,执行过程如下:
root@928c09c89c1c:/home/work/bag# git remote prune originPruning originURL: git@git.baijiashilian.com:LLL/gloud/bag.git * [pruned] origin/lozen
步骤三、拉取远端仓库代码
完成上面的两个步骤之后,我们就可以同步代码了,执行过程如下:
root@928c09c89c1c:/home/work/bag# git pullremote: Enumerating objects: 123, done.remote: Counting objects: 100% (123/123), done.remote: Compressing objects: 100% (88/88), done.remote: Total 123 (delta 69), reused 63 (delta 35), pack-reused 0Receiving objects: 100% (123/123), 99.65 KiB | 2.93 MiB/s, done.Resolving deltas: 100% (69/69), completed with 1 local object.From git.baijiashilian.com:LLL/gloud/bag * [new branch] lozen/remux -> origin/lozen/remux * [new branch] lozen/tc -> origin/lozen/tcAlready up to date.
可以看到,现在就没有问题了,已经成功把代码同步下来了,哈哈。完美!
整个问题的解决过程截图如下:
版权声明: 本文为 InfoQ 作者【liuzhen007】的原创文章。
原文链接:【http://xie.infoq.cn/article/19e478c140379576453bda97f】。文章转载请联系作者。
评论