use*_*561 79 git command-line-interface
我只有分支主人,我每次尝试"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)
Run Code Online (Sandbox Code Playgroud)
当我做"git pull origin master"时,我得到:
error: Couldn't set ORIG_HEAD
fatal: Cannot update the ref 'ORIG_HEAD'.
Run Code Online (Sandbox Code Playgroud)
我一直在寻找,但无法找到原因
Ski*_*ack 173
我和我的团队遇到了这个错误,无法更新本地参考,在SourceTree中进行拉动.
我们用了 :
git gc --prune=now
Run Code Online (Sandbox Code Playgroud)
这将删除任何应该解决问题的重复引用对象.
以下是一些链接,您可以在其中了解有关git引用和修剪的更多信息:
小智 68
我解决了如下:
git remote prune origin
小智 35
使用 gitbach line commande,用于git update-ref
更新本地分支的引用:
$ git update-ref -d refs/remotes/origin/[locked branch name]
Run Code Online (Sandbox Code Playgroud)
然后拉使用 $ git pull
[locked branch name]
是由于提交 ID 不匹配而发生错误的分支的名称。
Abd*_*inu 21
git remote prune origin
rm .git/refs/remotes/origin/master
git fetch
git pull origin master
Run Code Online (Sandbox Code Playgroud)
逐步运行上面的命令
cmt*_*kur 13
这对我来说非常有效:
rm -rf .git/packed-refs .git/rr-cache
Run Code Online (Sandbox Code Playgroud)
out*_*nds 10
我发现同样的错误消息试图从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'.
Run Code Online (Sandbox Code Playgroud)
解决方法如下
git reflog
找到最后一次提交的编号git reset --hard <numnber>
重置为上次提交 git pull origin master
再次拉,没有错误the*_*ant 10
这里发生了什么事?对远程分支的本地引用已更改,因此当您运行时git pull
,git 找不到任何相应的远程分支,因此失败。
git remote prune origin
Run Code Online (Sandbox Code Playgroud)
实际上清理了这个本地引用,然后git pull
再次运行。
--dry-run
建议 - 请选择安全选项运行
Windows 用户经常会遇到这个问题
git pull
Run Code Online (Sandbox Code Playgroud)
给出错误: 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
Run Code Online (Sandbox Code Playgroud)
原因 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)
Run Code Online (Sandbox Code Playgroud)
消除原因(请参阅上面的确切原因)。
git pull
Run Code Online (Sandbox Code Playgroud)
例如:创建分支命名策略,例如全部为小写字母;或小写最后一个斜杠前的字母。或者一些智能钩子,检测违规。(但请注意:在原因 a)问题仅在 Windows 上,而不是在 linux 上)。
问题是 windows 将这些分支(来自示例 1 和 2)存储在.git
文件夹中
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
Run Code Online (Sandbox Code Playgroud)
并且在原因 a)窗口无法区分大小写的差异,因此窗口上的 git 变得疯狂。
在原因 b) 中,您不能拥有与文件 ( feature/release2021/
) 同名的文件夹(例如feature/release2021
)。
通常有效的短期解决方法(直到您消除了原因)是:
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)
Run Code Online (Sandbox Code Playgroud)
小智 8
尝试在git仓库根文件夹中使用此命令:
rm .git/logs/refs/remotes/origin/master
Run Code Online (Sandbox Code Playgroud)
小智 6
对我有用的是:
git config --global fetch.prune true
Run Code Online (Sandbox Code Playgroud)
现在它继续自动运行修剪。
我已经删除了分支的本地引用:
git branch -d -r REPO/.git/refs/remotes/origin/BRANCHNAME
Run Code Online (Sandbox Code Playgroud)
然后我就可以进行抓取了。
或者更彻底
rm -rf REPO/.git/refs/remotes/origin
Run Code Online (Sandbox Code Playgroud)
这也每次都有效。
归档时间: |
|
查看次数: |
74368 次 |
最近记录: |