我只有分支主人,每当我尝试“git pull”时我都会收到此错误:
error: Couldn't set refs/remotes/origin/master
From /var/lib/git/xxx/project
! a0f80ea..49177a3 master -> origin/master (unable to update local ref)
当我做“git pull origin master”时,我得到:
error: Couldn't set ORIG_HEAD
fatal: Cannot update the ref 'ORIG_HEAD'.
我一直在寻找,但无法找到原因
答案 0 :(得分:133)
我和我的团队遇到了这个错误,无法更新本地参考,这是在吸引SourceTree时。
我们用过:
git gc --prune=now
这将删除任何应该解决问题的重复引用对象。
以下是一些链接,您可以在其中了解有关git引用和修剪的更多信息:
答案 1 :(得分:41)
我解决了如下:
git remote prune origin
答案 2 :(得分:25)
使用gitbach行命令,使用git update-ref
更新本地分支的引用:
$ git update-ref -d refs/remotes/origin/[locked branch name]
然后使用$ git pull
[locked branch name]
是由于提交ID不匹配而发生错误的分支的名称。
答案 3 :(得分:8)
我发现同样的错误消息试图从Bitbuck Repo拉入我的lokal副本。也只有一个Branche Master,命令git pull origin master
导致此错误消息
From https://bitbucket.org/xxx
* branch master -> FETCH_HEAD
error: Couldn't set ORIG_HEAD
fatal: Cannot update the ref 'ORIG_HEAD'.
解决方案如下
git reflog
找到最后一次提交的号码git reset --hard <numnber>
重置为上次提交git pull origin master
再次无误拉答案 4 :(得分:7)
确保执行git pull
的用户与创建存储库的用户相同。文件权限不正确。
答案 5 :(得分:5)
尝试在git信息库根文件夹中使用此命令:
rm .git/logs/refs/remotes/origin/master
答案 6 :(得分:4)
Windows 用户经常会遇到这个问题
git pull
给出错误:error: cannot lock ref
unable to update local ref
原因 a) 有多个分支,其 从开头到任何斜线(或到结尾)的名称,仅大小写不同。
Branch name clashing (upper/lower case)
#######################################
# Example 1)
#############################
feature/releasecandidate/fix123
feature/releaseCandidate/improveFeature789
------------------------
^
Identical from beginning up to a slash (here the 2nd one)
except for the marked letter, where the upper/lower case differs
# Example 2)
#############################
releaseBranch
releasebranch
-------------
^
Identical from beginning to the end
except for the marked letter
原因 b) 也是 linux 上的一个问题:一个分支是另一个分支的前缀,带有斜线边界:
Prefix with slash-boundary
#######################################
# Example 1) - also a problem on linux
#############################
feature/release2021
feature/release2021/fixIssue07
^
slash boundary
# Example 2)
#############################
feature/release2022
feature/Release2022/fixIssue99
^ ^
differing case slash boundary
(problem on
windows)
消除原因(参见上面的确切原因)。
# inspect your branches, to see if you have the upper/lower case problem
git ls-remote --heads YOUR-GIT-URL
例如:创建分支命名策略,例如全部为小写字母;或小写最后一个斜杠前的字母。或者一些智能钩子,检测违规。 (但请注意:原因 a)问题仅在 Windows 上,而不是在 linux 上。
问题是 windows 将这些分支(来自示例 1 和 2)存储在 .git
文件夹中
# inspect the files/folders under
.git/refs/remotes/origin/
并且在原因a)窗口无法区分 大写/小写的差异,所以窗口上的 git 变得疯狂。
在原因 b) 中,您不能拥有与文件 (feature/release2021/
) 同名的文件夹(例如 feature/release2021
)。
通常有效的短期解决方法(直到您消除原因)是:
git pack-refs --all
# delete the contents of .git/refs/remotes/origin/*
rm -rf .git/refs/remotes/origin/*
git pull; git pull; git pull # all good? yes!
答案 7 :(得分:3)
对我有用的是:
git config --global fetch.prune true
现在,它会继续自动运行修剪。
答案 8 :(得分:3)
rm .git/refs/remotes/origin/master
对我有用!
答案 9 :(得分:2)
我已经删除了分支的本地引用:
git branch -d -r REPO/.git/refs/remotes/origin/BRANCHNAME
然后我就可以去取东西了。
或者更彻底
rm -rf REPO/.git/refs/remotes/origin
这也每次都有效。
答案 10 :(得分:2)
这里发生了什么事?
对远程分支的本地引用已更改,因此,当您运行git pull
时,git找不到任何相应的远程分支,因此会失败。
git remote prune origin
实际上会清除此本地引用,然后再次运行git pull
。
建议-为了安全起见,请使用--dry-run
选项运行
答案 11 :(得分:1)
在我使用不区分大小写的文件系统的OSX上发生了这种情况。不知何故,另一位开发人员推出了一个名称相同但案例不同的分支:My-Branch
vs my-branch
。
我已经签出My-Branch
并收到错误&#34;无法更新本地参考&#34;当我执行拉取时可能是因为文件系统认为My-Branch
== my-branch
。
由于我们使用Github,我可以通过Github的GUI删除其中一个分支来解决问题。
答案 12 :(得分:1)
这可能是一个非常利基的情况,但是:我在MacBook Pro的Parallels VM上运行Windows,并将本地存储库存储在与MacOS共享的VM磁盘上。
如果我从Windows VM上的存储库中的Mac应用程序中打开了文件,有时会收到“无法更新本地引用”错误。发生这种情况时,解决方案是直接关闭文件或退出Mac应用。
答案 13 :(得分:1)
再次克隆存储库,并在已损坏的项目中复制.git文件夹。
答案 14 :(得分:1)
我遇到了同样的错误,我正在Eclipse中进行更新,但遇到了很多错误。 因此,我尝试从DOS命令窗口进行更新,并遇到了同样的问题。
然后我尝试了解决方案“ git gc --prune = now” 这给出了消息,指出文件已锁定在refs目录中。
Eclipse必须已锁定“ refs”目录中的某些内容。
我发现的解决方案是简单地关闭Eclipse。
然后,我使用“ git PULL”命令从DOS更新了存储库,一切正常。
答案 15 :(得分:1)
我通过删除锁定的分支文件解决了这个问题。它可能看起来很粗糙,我不知道它为什么起作用,但它解决了我的问题(即您遇到的相同错误)
已删除:
.git/refs/remotes/origin/[locked branch name]
然后我就跑了
git fetch
并且git文件自我恢复,完全修复
答案 16 :(得分:0)
一个命令解决方案[适用于 Linux/bash 用户]
sudo chown username -R .git
(将“用户名”替换为您的用户名)
如果文件的所有者是 sudo,请使用 sudo。
sudo rm .git/logs/refs/remotes/origin/master
答案 17 :(得分:0)
这对于 Windows 来说已经足够了:
<块引用>git pack-refs --all
答案 18 :(得分:0)
删除文件.git / logs / refs / remotes / origin / [锁定的分支名称]
答案 19 :(得分:0)
这对我有用
rm .git/logs/refs/remotes/origin/master
答案 20 :(得分:0)
我的debian服务器上存在同样的问题,因为磁盘已满。由于设备上没有剩余空间,因此无法创建临时文件。清理完一些文件后,效果很好。
答案 21 :(得分:0)
从PC用户那里说 - 重启。
老实说,它对我有用。我已经解决了两个我认为是腐败的奇怪的git问题。
答案 22 :(得分:0)
如果您最近更改了密码并且有一些集成Windows和Linux登录的奇特内容,也会发生此错误(无法更新本地参考)。