重命名分支后无法打开 FETCH_HEAD [英] Cannot open FETCH_HEAD after renaming a branch

查看:31
本文介绍了重命名分支后无法打开 FETCH_HEAD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重命名master"分支(使用 Sourcetree)后,我无法再获取远程存储库中所做的更改.

After having renaming the 'master' branch (using Sourcetree), I can't fetch anymore the changes done in the remote repository.

我得到错误:

error: cannot open .git/FETCH_HEAD: Permission denied

当我打开这个文件时,我看到引用的分支仍然设置为 branch 'master'.

When I open this file, I see that the referenced branch is still set toward branch 'master'.

查看远程存储库,我看到一个名为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.

我尝试手动编辑 FETCH_HEAD(更改完整的 SHA 和指向的分支),但我仍然收到此错误.当然,我不能像以前那样重命名主分支,因为始终存在名为master"的分支.

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:

  1. 我实际上已经重命名了一个分支(但这似乎不是主要原因)
  2. 我还更新了用户名和电子邮件地址(这可以支持我作为其他用户执行了各种操作的分析)
  3. 由于SourceTree 的已知错误,某些分支无法获取(突然停止跟踪一些远程分支)
  1. I have actually renamed a branch (but that doesn't seem to be the major causek)
  2. I have also updated username and email address (this can support the analysis that I have performed various operations as some other user)
  3. Some branches was unable to be fetched certainly because of a known bug of SourceTree (which have suddenly stopped tracking of some remote branches)

由于使用 chown 命令似乎没有效果,我终于通过以下过程解决了我的问题:

As using chown command doesn't seem to be effective, I have finally resolved my issue using the following process:

  1. 使用命令 rm -f .git/FETCH_HEAD 删除被拒绝的文件(如 this answer 中所述)
  2. 使用命令 git branch -u 重新连接未跟踪的分支(如 此评论)
  1. Removing the denied file using the command rm -f .git/FETCH_HEAD (as described in this answer)
  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆