Git 致命:无法锁定引用

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

Git fatal: cannot lock ref

gitgit-branchgit-checkout

提问by Tommaso Guerrini

I'm trying to create a branch on the current branch on my Ubuntu guest. Unfortunately I keep getting this error:

我正在尝试在我的 Ubuntu 来宾上的当前分支上创建一个分支。不幸的是,我不断收到此错误:

git checkout -b origin/feature/IF-53-change-validation-window/Tommaso
fatal: cannot lock ref 'refs/heads/origin/feature/IF-53-change-validation-window/Tommaso': 
'refs/heads/origin/branch' exists; 
cannot create 'refs/heads/origin/branch/Tommaso'

I tried git gc --prune=nowas suggested here link, but keep getting the same error.

git gc --prune=now按照此处链接的建议进行了尝试,但不断收到相同的错误。

回答by cmbuckley

You shouldn't be checking out branches like that. Assuming that branch exists on origin, you should do the following:

你不应该像那样检查分支。假设分支存在于原点,您应该执行以下操作:

git checkout feature/IF-53-change-validation-window/Tommaso

If you run git branchI expect you will see local branches with originin the name.

如果您运行,git branch我希望您会看到origin名称中带有本地分支。

The format git checkout Xis shorthand for "look for a local branch Xand check that out if it exists; otherwise look for a remote branch Xand check that out locally (git checkout -b X origin/X)."

该格式git checkout X是“查找本地分支X并检查它是否存在;否则查找远程分支X并在本地进行检查 ( git checkout -b X origin/X)”的简写。

If you are creating a new local branch, you will often do the following:

如果您正在创建一个新的本地分支,您通常会执行以下操作:

git checkout -b new-branch

This will create a new branch pointing at the same commit as you had checked out previously.

这将创建一个新分支,指向与您之前签出的相同的提交。

To fix your current state, you can likely do this (see here):

要修复您当前的状态,您可能可以这样做(请参阅此处):

git update-ref -d refs/heads/origin/branch

回答by Deepak

Sometimes this can happen if the name of the branch you create doesn't match git naming conventions or those set by you projects git administrator. Changing the name to one that does, can can fix this issue.

有时,如果您创建的分支名称与 git 命名约定或您的项目 git 管理员设置的命名约定不匹配,则会发生这种情况。将名称更改为可以解决此问题的名称。