解决 git pull 本地引用更新失败
git remote prune origin
问题
git checkout master
Switched to branch ‘master’
Your branch is behind ‘origin/master’ by 35 commits, and can be fast-forwarded.
(use “git pull” to update your local branch)
git pull
error: cannot lock ref ‘refs/remotes/origin/fix/po_sent_email_histories_pdf_price_wrong’: ‘refs/remotes/origin/fix’ exists; cannot create ‘refs/remotes/origin/fix/po_sent_email_histories_pdf_price_wrong’
From code.shopperplus.com:rain/console
! [new branch] fix/po_sent_email_histories_pdf_price_wrong -> origin/fix/po_sent_email_histories_pdf_price_wrong (unable to update local ref)
解决
git gc --prune=now
Enumerating objects: 217374, done.
Counting objects: 100% (217374/217374), done.
Delta compression using up to 8 threads
Compressing objects: 100% (51634/51634), done.
Writing objects: 100% (217374/217374), done.
Total 217374 (delta 168535), reused 212702 (delta 164244)
Checking connectivity: 217374, done.
git remote prune origin
Pruning origin
URL: git@code.shopperplus.com:rain/console.git
- [pruned] origin/170109
- [pruned] origin/AR4
- [pruned] origin/Add-link-to-Tracking-Number
…
git pull
From code.shopperplus.com:rain/console
- [new branch] fix/po_sent_email_histories_pdf_price_wrong -> origin/fix/po_sent_email_histories_pdf_price_wrong
Updating 2778783a7..f30a80f48
Fast-forward
Gemfile | 1 -
Gemfile.lock | 26 ——
app/controllers/application_controller.rb | 1 -…
git status
On branch master
Your branch is up to date with ‘origin/master’.nothing to commit, working tree clean
原因
error: cannot lock ref ‘refs/remotes/origin/fix/po_sent_email_histories_pdf_price_wrong’: ‘refs/remotes/origin/fix’ exists; cannot create ‘refs/remotes/origin/fix/po_sent_email_histories_pdf_price_wrong’
refs/remotes/origin/fix
已经存在,导致 refs/remotes/origin/fix/po_sent_email_histories_pdf_price_wrong
无法创建。更好的做法,本地清掉 refs/remotes/origin/fix
即可。不过上面的命令全清也不错,公司的代码分支是有点乱😅
Reference
git pull fails “unable to resolve reference” “unable to update local ref”