简体   繁体   English

如何修复 git 存储库以删除已存在文件夹的 update_ref 错误?

[英]How do I fix the git repo to remove a update_ref error for a folder which already exists?

I get the following error when I try to git push a branch documentation/manifest :当我尝试git push分支documentation/manifest时出现以下错误:

error: update_ref failed for ref 'refs/remotes/origin/documentation/manifest': cannot lock ref 'refs/remotes/origin/documentation/manifest': 'refs/remotes/origin/documentation' exists; cannot create 'refs/remotes/origin/documentation/manifest'

The steps which led up to this error were:导致此错误的步骤是:

  1. cloned from the remote repo (github)从远程仓库(github)克隆
  2. created a local branch documentation/manifest and did some work on it, committing the work.创建了一个本地分支documentation/manifest并对其进行了一些工作,提交了工作。
  3. pushed the branch.推了树枝。 Couldn't push because there was an existing 3 year old, stale, branch called documentation .无法推送,因为有一个现有的 3 年陈旧的分支,名为documentation
  4. Deleted the branch documentation on github.删除了 github 上的分支documentation
  5. pushed again.又被推了。 Branch pushed OK to remote, I can confirm it is there, however the above error appears after every time I push.分支将 OK 推送到远程,我可以确认它在那里,但是每次推送后都会出现上述错误。 Given that I presume it is a local error.鉴于我认为这是一个本地错误。

I've looked up some similar questions such as Git error when pushing - update_ref failed , however this was dealing with a different cause - it was not clear to me if the suggested solutions to that answer would help in this case, and as they seemed quite low-level they could equally well mess things up in a different way.我查看了一些类似的问题,例如Git 推送时出错 - update_ref failed ,但是这是处理不同的原因 - 我不清楚该答案的建议解决方案是否会在这种情况下有所帮助,并且看起来相当低级的他们同样可以以不同的方式把事情搞砸。

So, what do I need to do to get rid of this error whenever I push this branch?那么,每当我推送这个分支时,我需要做什么来摆脱这个错误?

I believe the problem is that you still have a local reference to the former remote documentation branch, because the error messages says cannot create 'refs/remotes/origin/documentation/manifest' , which would indeed be the case if refs/remotes/origin/documentation already exists as a regular file.我认为问题在于您仍然对以前的远程documentation分支有本地引用,因为错误消息说cannot create 'refs/remotes/origin/documentation/manifest' ,如果refs/remotes/origin/documentation确实是这种情况refs/remotes/origin/documentation已作为常规文件存在。

Removing the old local references should solve this problem:删除旧的本地引用应该可以解决这个问题:

git fetch -p

And if that doesn't work, you can even manually delete the problem file:如果这不起作用,您甚至可以手动删除问题文件:

rm .git/refs/remotes/origin/documentation

which you know is safe, since you deleted the documentation branch on origin.您知道这是安全的,因为您删除了原始documentation分支。

Relevant reference:相关参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM