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
Git fatal: cannot lock ref
提问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=now
as 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 branch
I expect you will see local branches with origin
in the name.
如果您运行,git branch
我希望您会看到origin
名称中带有本地分支。
The format git checkout X
is shorthand for "look for a local branch X
and check that out if it exists; otherwise look for a remote branch X
and 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 管理员设置的命名约定不匹配,则会发生这种情况。将名称更改为可以解决此问题的名称。