可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Using git 1.6.4.2, when I do a git pull I get this error:
error: unable to resolve reference refs/remotes/origin/LT558-optimize-sql: No such file or directory From git+ssh://remoteserver/~/misk5 ! [new branch] LT558-optimize-sql -> origin/LT558-optimize-sql (unable to update local ref) error: unable to resolve reference refs/remotes/origin/split-css: No such file or directory ! [new branch] split-css -> origin/split-css (unable to update local ref)
I've tried git remote prune origin, but it didn't help.
回答1:
Try cleaning-up your local repository with:
$ git gc --prune=now $ git remote prune origin
man git-gc(1):
git-gc - Cleanup unnecessary files and optimize the local repository git gc [--aggressive] [--auto] [--quiet] [--prune= | --no-prune] Runs a number of housekeeping tasks within the current repository, such as compressing file revisions (to reduce disk space and increase performance) and removing unreachable objects which may have been created from prior invocations of git add. Users are encouraged to run this task on a regular basis within each repository to maintain good disk space utilization and good operating performance.
man git-remote(1):
git-remote - manage set of tracked repositories git remote prune [-n | --dry-run] Deletes all stale remote-tracking branches under . These stale branches have already been removed from the remote repository referenced by , but are still locally available in "remotes/".
回答2:
Happened to me as well. In my case, the bad ref was master, and I did the following:
rm .git/refs/remotes/origin/master git fetch
This made git restore the ref file. After that everything worked as expected again.
回答3:
This did the job for me:
git gc --prune=now
回答4:
For me it worked to remove the files that are throwing errors from the folder
.git/refs/remotes/origin/
回答5:
I had this same issue and solved it by going to the file it was erroring on:
\repo\.git\refs\remotes\origin\master
This file was full of nulls, I replaced it with the latest ref from github.
回答6:
This works for me:
git gc --prune=now
On SourceTree requires one more pull to fix.
回答7:
Execute the following commands:
rm .git/refs/remotes/origin/master git fetch git branch --set-upstream-to=origin/master
Just in case, if you need to know what is .git/refs/remotes/origin/master, you would read the Remotes section in Git References.
回答8:
In my case, the problem was solved after I've deleted all the remove reference files under .git
If you look at the message, it would tell you which files you need to delete (specifically)
The files to delete sit under .git/refs/remotes
I've just deleted all the files there, and ran gc prune
git gc --prune=now
After that, everything works just fine.
回答9:
git fetch --prune fixed this error for me:
[marc.zych@marc-desktop] - [~/code/driving] - [Wed May 10, 02:58:25] [I]> git fetch error: cannot lock ref 'refs/remotes/origin/user/janek/integration/20170505': 'refs/remotes/origin/user/janek/integration' exists; cannot create 'refs/remotes/origin/user/janek/integration/20170505' From github.com:zooxco/driving ! [new branch] user/janek/integration/20170505 -> origin/user/janek/integration/20170505 (unable to update local ref) From github.com:zooxco/driving [marc.zych@marc-desktop] - [~/code/driving] - [Wed May 10, 02:58:30] [I]> git fetch --prune - [deleted] (none) -> origin/user/janek/integration
This assumes that the offending branch was deleted on the remote, though.
回答10:
To Answer this in very short, this issue comes when your local has some information about the remote and someone changes something which makes remote and your changes unsync.
I was getting this issue because someone has deleted remote branch and again created with the same name.
For dealing with such issues, do a pull or fetch from remote.
git remote prune origin
or if you are using any GUI, do a fetch from remote.

回答11:
If git gc --prune=now dosen't help you. (bad luck like me)
What I did is remove the project in local, and re clone the whole project again.
回答12:
I was able to work with
git remote update --prune
回答13:
I had same issue. i follow following steps
1)switch your branch which having issue to other branch
2) delete that branch
3) checkout again.
Note:- You can stash you uncommitted changes and put it back again.
回答14:
Try this:
git pull origin Branch_Name
Branch_Name, the branch which you are currently on.
If you do only a git pull, it pulls all other created branch name as well.
So is the reason you are getting this:
! [new branch] split-css -> origin/split-css (unable to update local ref)
回答15:
For me, I had a local branch named feature/phase2 and the remote branch was named feature/phase2/data-model. The naming conflict was the cause of the problem, so I deleted my local branch (you could rename it if it had anything you needed to keep)
回答16:
I had the same problem with composer update. But for me it only worked after I cleared the composer cache and after deleting the content of the vendor folder:
rm -rf vendor/* git gc --prune=now git pull composer clear-cache composer update my/package
回答17:
Got this issue when trying to clone from a git bundle created file, none of the other answers worked because I couldn't clone the repo (so git gc and removing/editing files was out of the question).
There was however another way to fix this - the source file of a .bundle file was begining with:
# v2 git bundle 9a3184e2f983ba13cc7f40a820df8dd8cf20b54d HEAD 9a3184e2f983ba13cc7f40a820df8dd8cf20b54d refs/heads/master 9a3184e2f983ba13cc7f40a820df8dd8cf20b54d refs/heads/master PACK.......p..x...Kj.0...: (and so on...)
Simply removing the fourth line with vim fixed the issue.
回答18:
I had this issue while using SourceTree. I tried to pull again and it worked. I think I Was witching branches (checkout) too fast :).
My situation is a bit different from the poster's because my repository has been relatively cooperative, without any apparent corruption.
回答19:
Had the same msg but with a directory, got a failed msg on pull.
git --prone did not help me either. Turns out there was a file with the same name as a directory created remotely.
Had to go to .git\logs\refs\remotes\origin and erase the locale file - then pull again, all good.
回答20:
# remove the reference file of the branch "lost" rm -fv ./.git/refs/remotes/origin/feature/v1.6.9-api-token-bot-reader # get all the branches from the master git fetch --all # git will "know" how-to handle the issue from now on # From github.com:futurice/senzoit-www-server # * [new branch] feature/v1.6.9-api-token-bot-reader -> # origin/feature/v1.6.9-api-token-bot-reader # and push your local changes git push
回答21:
Just ran into the problem today.
With SourceTree on Windows Servers, you may need to run it as an Administrator. That fixes my problem of "unable to update local ref" on Atlassian Source Tree 2.1.2.5 on a Windows Server 2012 R2 in domain.
回答22:
I was getting this error once running git fetch:
error: cannot lock ref 'refs/remotes/origin/branchname': ref refs/remotes/origin/featureEmailTemplate is at 45c5f2ab... but expected d48af9... from https://.../... (unable to update local ref)
The following command fixed the problem :
git gc --prun=now