臭名昭著的 Git 错误:远程拒绝(无法锁定)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12416643/
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-10 14:35:38  来源:igfitidea点击:

Notorious Git Error: remote rejected (failed to lock)

gitgithub

提问by Lost

I am trying to push to a branch from my local to the origin. The branch name and the path is same. I have been pushing and pulling from this branch for a while and never had a problem. But suddenly, it started behaving badly. Last time when I tried to push to origin with following command:

我试图从我的本地推送到一个分支到原点。分支名称和路径相同。我已经从这个分支推拉了一段时间,从来没有遇到过问题。但突然间,它开始表现不佳。上次我尝试使用以下命令推送到原点时:

git push origin feature/Prizefulfilment

It gives me following errror:

它给了我以下错误:

72c6c1da98e5cff4484e254a538d9e3b472156ff but expected 0000000000000000000000000000000000000000

I have Googled around but did not find a quite satisfying solution to it yet.

我已经谷歌搜索,但还没有找到一个非常令人满意的解决方案。

My exact error looks like following:

我的确切错误如下所示:

$ git push origin feature/Prizefulfilment
Counting objects: 126, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (75/75), done.
Writing objects: 100% (78/78), 8.83 KiB, done.
Total 78 (delta 61), reused 0 (delta 0)
error: Ref refs/heads/feature/Prizefulfilment is at 72c6c1da98e5cff4484e254a538d9e3b472156ff but expected 0000000000000000000000000000000000000000
remote: error: failed to lock refs/heads/feature/Prizefulfilment
To [email protected]:OpusOneSCRUM
 ! [remote rejected] feature/Prizefulfilment -> feature/Prizefulfilment (failed to lock)
error: failed to push some refs to '[email protected]:OpusOneSCRUM'`

Any ideas?

有任何想法吗?

回答by VonC

 git push feature/prizeFulfilment: feature/Prizefulfilment

That is similar to this answer:

这类似于这个答案

For the record, I believe the root cause of this problem was the difference in capitalisation between the local and remote branch names, and the case-insensitive nature of the Windows share that hosted the remote repository.

We just encountered this exact same error and were able to resolve the problem simply by renaming the local branch to match the capitalisation of the existing remote branch.

作为记录,我认为这个问题的根本原因是本地和远程分支名称之间的大小写差异,以及托管远程存储库的 Windows 共享不区分大小写的性质。

我们刚刚遇到了这个完全相同的错误,并且能够通过重命名本地分支以匹配现有远程分支的大小写来解决问题。

Try and make sure to use the same capitalization between local and remote branches.

尝试并确保在本地和远程分支之间使用相同的大小写

You second command make the link between the prizeFulfilmentand remote Prizefulfilmentexplicit, which is why it worked. But it isn't a good solution to keep a local branch with that kind of difference.

您的第二个命令使prizeFulfilment远程和远程之间的链接Prizefulfilment显式,这就是它起作用的原因。但是,保留具有这种差异的本地分支机构并不是一个好的解决方案。

回答by amleszk

I saw this error happen because a previous branch existed with the same name as my new branch path name. Example:

我看到此错误发生是因为前一个分支与我的新分支路径名称同名。例子:

  • Remote has branch: some_feature
  • Local has branch: some_feature/some_subfeature
  • Local pushes branch some_feature/some_subfeatureto Remote
  • Remote has error: (failed to lock)
  • 远程有分支: some_feature
  • 本地有分行: some_feature/some_subfeature
  • 本地推送分支some_feature/some_subfeature到远程
  • 遥控器有错误: (failed to lock)

Solutions:

解决方案:

  • Rename local branch some_feature/some_subfeatureto foo/some_subfeature
  • Delete remote branch some_feature
  • 将本地分支重命名some_feature/some_subfeaturefoo/some_subfeature
  • 删除远程分支 some_feature

回答by Marek R

Another possible reason of problems present also on case sensitive systems is conflicting breaches names.

区分大小写的系统也存在问题的另一个可能原因是冲突名称冲突。

If remote repository contains branch a/band you are trying push branch a/b/csame error will be reported by git (definitely this error description should be improved).

如果远程存储库包含分支a/b并且您正在尝试推送分支a/b/c,git 将报告相同的错误(这个错误描述肯定应该改进)。

https://coderwall.com/p/qkofma/a-caution-about-git-branch-names-with-shttps://ocroquette.wordpress.com/2011/07/10/git-failed-to-lock/

https://coderwall.com/p/qkofma/a-caution-about-git-branch-names-with-s https://ocroquette.wordpress.com/2011/07/10/git-failed-to-lock /

回答by jovanchohan

What happened to me was that git was changing the capitalization of my local branch. I had an old branch named Feature/blahBlah and a new branch named feature/fooBar. The latter was renamed automatically to Feature/fooBar since git stores branches as folders and I couldn't have the same folder name with different capitalization.

发生在我身上的是 git 改变了我本地分支的大小写。我有一个名为 Feature/blahBlah 的旧分支和一个名为 feature/fooBar 的新分支。后者被自动重命名为 Feature/fooBar,因为 git 将分支存储为文件夹,我不能使用不同大小写的相同文件夹名称。

To fix it, I had to go into .git/refs/heads and rename 'Feature' to 'feature'` so all branches would be consistent.

要修复它,我必须进入 .git/refs/heads 并将“Feature”重命名为“feature”`,以便所有分支保持一致。

回答by JBTPublic

In my case it was permissions not set up correctly in the git repository. I found the solution here: How to use group file permissions correctly on a git repository?

就我而言,是在 git 存储库中未正确设置权限。我在这里找到了解决方案:如何在 git 存储库上正确使用组文件权限?

The problem was when a new branch was created that contains a path (feature/Prizefulfilment), the folder "feature" is created in "refs/heads/" and the new folder had inherit the users group ID which prevented future users to use the same path.

问题是当创建一个包含路径(功能/Prizefulfilment)的新分支时,文件夹“功能”在“refs/heads/”中创建,并且新文件夹继承了用户组ID,这阻止了未来的用户使用相同的路径。

To solve this you have to set the setgid to all of the directories in the git repository so that the new folder inherit its group ID, rather than group ID of the user.

要解决此问题,您必须将 setgid 设置为 git 存储库中的所有目录,以便新文件夹继承其组 ID,而不是用户的组 ID。

chown -R git:git /path/to/repo
chmod -R g+rw /path/to/repo
find /path/to/repo -type d -print0 | xargs -0 chmod g+s

回答by Klaus Nji

In my case, I had checkout a branch with all lower case lettering. This caused an inconsistency between the remote branch and local branch names.

就我而言,我结帐了一个全小写字母的分支。这导致远程分支和本地分支名称不一致。

Remote branch was INT-4368-some-feature-details, whereas local branch was int-4368-some-feature-details.

远程分支是 INT-4368-some-feature-details,而本地分支是 int-4368-some-feature-details。

To fix, I went into .git\refs\heads\feature and renamed the branch name to match the remote. Then went to command line and ran

为了修复,我进入 .git\refs\heads\feature 并重命名分支名称以匹配远程。然后转到命令行并运行

git checkout INT-4368-some-feature-details

回答by MAITRAIYA MALI

Branch name of local and remote repo not matching in terms of capitalization, you can rename your local branch using this command :-

本地和远程仓库的分支名称在大小写方面不匹配,您可以使用以下命令重命名本地分支:-

git branch -m new-name

回答by Prem Kumar

When you get message like this,first do pull operation from remote branch.Then do push operation.When somebody pushes files to remote server,it will shift the master branch(in case remote branch is master,it can be any name) to some other place.You need to update this in the local repository,so that origin/master in the local repository will move forward.Then add files in the local repository and commit it.Then do push operation.It worked for me

当你收到这样的消息时,先从远程分支做pull操作,然后再做push操作。当有人把文件推送到远程服务器时,它会将master分支(如果远程分支是master,可以是任何名称)转移到一些其他地方。你需要在本地仓库中更新这个,这样本地仓库中的origin/master才会向前移动。然后在本地仓库中添加文件并提交。然后进行推送操作。它对我有用