Sourcetree/GIT - 拉动时无法锁定参考/参考损坏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47226069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:58:45  来源:igfitidea点击:

Sourcetree/GIT - Cannot lock ref/reference broken, when pulling

gitatlassian-sourcetreegit-pull

提问by Tom N.

A co-worker and I have been working on the same branch for a week, constantly pushing/pulling changes and all of a sudden today, I hit 'pull' to see if there were any changes I needed to pull and I got an error.

我和一个同事在同一个分支上工作了一个星期,不断地推/拉更改,今天突然间,我点击了“拉”,看看是否有我需要拉的任何更改,但出现错误.

This is in sourcetree by the way. The error was this:

顺便说一下,这是在 sourcetree 中。错误是这样的:

git -c diff.mnemonicprefix=false -c core.quotepath=false fetch origin
error: cannot lock ref 'refs/remotes/origin/angular_removal': unable to resolve reference 'refs/remotes/origin/angular_removal': reference broken
From https://bitbucket.org/colossus
 ! [new branch]        angular_removal -> origin/angular_removal  (unable to update local ref)

I'm in sourcetree, which has a terminal built in, but I can't seem to find a resolution here.

我在 sourcetree 中,它内置了一个终端,但我似乎无法在这里找到解决方案。

回答by Dudar

The error text was slightly different for me like: unable to update local ref it is [hash_code_1] but expected [hash_code_2].

错误文本对我来说略有不同,例如: unable to update local ref it is [hash_code_1] but expected [hash_code_2]

So the command like rm -rf .git/refs/remotes/origin/angular_removalhelped me only to do fetch once. Then the message would return again.

所以像这样的命令 rm -rf .git/refs/remotes/origin/angular_removal只帮助我获取一次。然后消息将再次返回。

What actually helped in this situation to fix the issue permanently was:

在这种情况下真正帮助永久解决问题的是:

  1. go into .git subfolder of my local repository;
  2. open packed-refs file;
  3. find the line with branch name from error message;
  4. remove it from this file;
  5. now you can do fetch or pull all you like.
  1. 进入我本地存储库的 .git 子文件夹;
  2. 打开packed-refs文件;
  3. 从错误消息中找到带有分支名称的行;
  4. 从这个文件中删除它;
  5. 现在你可以做任何你喜欢的 fetch 或 pull 操作。

回答by Raja Anbazhagan

The accepted solution provides details only about how OP got around the issue and it is not a definitive answer.

已接受的解决方案仅提供有关 OP 如何解决该问题的详细信息,而不是确定的答案。

For the sake of people like me who end up here from Google, Here is the solution that actually works.

为了像我这样从谷歌来到这里的人,这是真正有效的解决方案。

Lets say, if the error message looks like below,

让我们说,如果错误消息如下所示,

error: cannot lock ref 'refs/remotes/origin/angular_removal': unable to resolve reference 'refs/remotes/origin/angular_removal': reference broken

Here, the offending element is a corrupted file named refs/remotes/origin/angular_removalwhich resides in the .githidden folder.

在这里,有问题的元素是一个名为的损坏文件refs/remotes/origin/angular_removal,它位于.git隐藏文件夹中。

Inorder to fix this, run the following commands under your repository root directory.

为了解决这个问题,请在您的存储库根目录下运行以下命令。

rm .git/refs/remotes/origin/angular_removal
git fsck

The first command alone should fix the issue as gittries to reinitialize the missing references.

git尝试重新初始化丢失的引用时,第一个命令应该可以解决问题。

The command git fsckis to there just to check if the repository is in good health.

该命令git fsck只是为了检查存储库是否健康。



NOTE: The reffile would be of different for others. So make sure you are using the reffile name from the error message that you got.**

注意ref其他人的文件会有所不同。因此,请确保您使用的是ref收到的错误消息中的文件名。**

回答by Lucas Castro

Here are the steps that fixed it for me:

以下是为我修复它的步骤:

  1. Delete the file .git/packed_refs
  2. Do a pull.
  3. Run git pack-refsto recreate the packed_refs file.
  1. 删除文件 .git/packed_refs
  2. 拉一下。
  3. 运行git pack-refs以重新创建packed_refs 文件。

For reference, see: https://git-scm.com/docs/git-pack-refs

参考:https: //git-scm.com/docs/git-pack-refs

回答by Adam

I had a similar issue, but I couldn't push my commit from my local branch to the remote branch. Looking inside sourcetree under my remote branches, my branch suddenly didn't exist. I tried @Dudar answer, but the branch wasnt mentioned in the packed-refs file. So what I did was:

我有一个类似的问题,但我无法将我的提交从本地分支推送到远程分支。在我的远程分支下查看 sourcetree 内部,我的分支突然不存在。我尝试了@Dudar 的回答,但打包引用文件中没有提到该分支。所以我所做的是:

  1. go into .git\refs\remotes\origin\feature subfolder of my local repository;
  2. delete the file named as my branch causing the issue;
  3. push my changes
  1. 进入我本地存储库的 .git\refs\remotes\origin\feature 子文件夹;
  2. 删除名为 my branch 的文件导致问题;
  3. 推动我的改变

Note: My branch existed in a subfolder of origin called "feature".

注意:我的分支存在于一个名为“feature”的原始子文件夹中。

回答by Tom N.

Multiple solutions didn't quite resolve it but I ended up re-cloning

多个解决方案并没有完全解决它,但我最终重新克隆

回答by user3613932

Just happened to me as well; one of my ref branches under my alias was corrupted. Fix:

刚好也发生在我身上;我别名下的 ref 分支之一已损坏。使固定:

rm <root of repository>.git/refs/remotes/origin/<your alias>
git fetch

You can use rd /sinstead of rmon Windows.

您可以在 Windows 上使用rd /s而不是rm

Here are the detailed steps I took to fix the issue. You may choose to skip some of the steps below:

以下是我为解决此问题所采取的详细步骤。您可以选择跳过以下某些步骤:

  1. I first committed all my local changes in the local branch that was giving me the issue.
  2. Created git patchesfor my local branch.
  3. Deleted my local branch.
  4. Applied the following fix
  5. Checked out the remote branch after running git fetch
  6. Applied the necessary patch files to the local branch.
  1. 我首先在给我问题的本地分支中提交了所有本地更改。
  2. 为我的本地分支创建了git 补丁
  3. 删除了我的本地分支。
  4. 应用了以下修复
  5. 运行 git fetch 后检出远程分支
  6. 将必要的补丁文件应用到本地分支。

This made git restore the ref file. After that everything worked as expected again.

这使得 git restore ref 文件。之后,一切都再次按预期工作。

回答by arun8

 git pull

resulted in the following error.

导致以下错误。

error: cannot lock ref 'refs/remotes/origin/e2e/gb-feedback-test': is at 2962f77c6b4248a82efbd4d3c*******f but expected c3c0af7e310247b4e8dfd94883******5
From https://company.com
 ! c3c0af7e3..2962f77c6  branch-name -> origin/branch-name  (unable to update local ref)

It was resolved by

它被解决了

git pull origin master

回答by Anindya Sankar Dasgupta

Do a

做一个

git gc --auto 

and then do

然后做

git pull