重命名分支后无法打开FETCH_HEAD [英] Cannot open FETCH_HEAD after renaming a branch
问题描述
我得到错误:
error:can not open .git / FETCH_HEAD:Permission denied
当我打开这个文件时,我发现被引用的分支仍然被设置为分支'master'
。 p>
看看远程存储库,我看到名为'master'的分支依然存在,除了重新命名的分支,我合并了最后的更改。我认为在某处出现了问题,重命名在远程存储库中未正确复制。
我试图手动编辑 FETCH_HEAD
(改变完整的SHA和尖锐的分支),但是我仍然得到这个错误。当然,由于名为'master'的分支总是存在,所以我不能再重新命名。
有没有办法解决这个问题?事实上,这个问题似乎(可能)是由于各种因素的综合作用:
- 我已经重新命名了一个分支(但这似乎不是主要的原因)
- 我也更新了用户名和电子邮件地址(这可以支持我作为其他用户执行过各种操作的分析)
- 由于 SourceTree的已知bug(它突然停止了某些远程分支的跟踪)
因为使用 chown
命令似乎并不有效,所以我最终使用以下过程解决了我的问题: p>
之后,能够获取所有远程分支,现在,所有远程分支都与我的本地存储库正确同步。
After having renaming the 'master' branch (using Sourcetree), I can't fetch anymore the changes done in the remote repository.
I get the error:
error: cannot open .git/FETCH_HEAD: Permission denied
When I open this file, I see that the referenced branch is still set toward branch 'master'
.
Taking a look at the remote repository, I saw that a branch with named 'master' still exists, in addition to the renamed branch where I merged my last changes. I think there have got a problem somewhere and the renaming was not replicated correctly in the remote repository.
I have tried to manually edit the FETCH_HEAD
(changing the full SHA and the pointed branch), but I still get this error. Of course, I can not rename again as before my main branch, since a branch named 'master' is always present.
Is there a way around this problem?
In fact, it seems that this problem is (potentially) due to the combination of various factors:
- I have actually renamed a branch (but that doesn't seem to be the major causek)
- I have also updated username and email address (this can support the analysis that I have performed various operations as some other user)
- Some branches was unable to be fetched certainly because of a known bug of SourceTree (which have suddenly stopped tracking of some remote branches)
As using chown
command doesn't seem to be effective, I have finally resolved my issue using the following process:
- Removing the denied file using the command
rm -f .git/FETCH_HEAD
(as described in this answer) - Reconnecting the untracked branches using the command
git branch -u
(as described in this comment)
After that, I was able to fetch all the remote branches, and now, all is correctly synchronized with my local repository.
这篇关于重命名分支后无法打开FETCH_HEAD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!