Git 和讨厌的“错误:无法锁定现有信息/引用致命”

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

Git and nasty "error: cannot lock existing info/refs fatal"

git

提问by AnnD

After cloning from remote git repository (at bettercodes) I made some changes, commited and tried to push:

从远程 git 存储库(在 Bettercodes)克隆后,我做了一些更改,提交并尝试推送:

git push origin master

Errors with:

错误:

error: cannot lock existing info/refs
fatal: git-http-push failed

错误:无法锁定现有信息/引用
致命:git-http-push 失败

This case regards already existing repository.

这种情况涉及已经存在的存储库。

What I did before, was:

我之前做的是:

  1. git config –global http.sslVerify false
  2. git init
  3. git remote add [url]
  4. git clone
  5. change data
  6. git commit
  1. git config –global http.sslVerify false
  2. git init
  3. git remote add [url]
  4. git clone
  5. 更改数据
  6. git commit

At 'bettercodes' I have no access to git log.

在 'bettercodes' 我无法访问 git log。

I'm using Windows. The detailed error was:

我正在使用 Windows。详细的错误是:

C:\MyWorkStuff\Projects\Ruby\MyProject\>git push origin master
Unable to create branch path https://user:[email protected]/myproject/info/
error: cannot lock existing info/refs
fatal: git-http-push failed

I cloned before, then changed the code and committed.

我之前克隆过,然后改了代码就提交了。

回答by arno_v

For me this worked:

对我来说这有效:

git remote prune origin

git remote prune origin

Since this answer seems to help a lot of people, I dug a little bit into what actually happens here. What this will do is remove references to remote branches in the folder .git/refs/remotes/origin. So this will not affect your local branches and it will not change anything remote, but it will update the local references you have to remote branches. It seems in some cases these references can contain data Git cannot handle correctly.

由于这个答案似乎对很多人有帮助,因此我深入了解了这里实际发生的情况。这将删除对文件夹中远程分支的引用.git/refs/remotes/origin。所以这不会影响你的本地分支,也不会改变远程的任何东西,但它会更新你对远程分支的本地引用。在某些情况下,这些引用似乎包含 Git 无法正确处理的数据。

回答by kiran.gilvaz

回答by johnnyclem

This happened to me when my git remote (bitbucket.org) changed their IP address. The quick fix was to remove and re-add the remote, then everything worked as expected. If you're not familiar with how to remove and re-add a remote in git, here are the steps:

当我的 git remote (bitbucket.org) 更改了他们的 IP 地址时,这发生在我身上。快速修复是删除并重新添加遥控器,然后一切都按预期工作。如果您不熟悉如何在 git 中删除和重新添加遥控器,请按以下步骤操作:

  1. Copy the SSH git URL of your existing remote. You can print it to the terminal using this command:

    git remote -v

  1. 复制现有遥控器的 SSH git URL。您可以使用以下命令将其打印到终端:

    git remote -v

which will print out something like this:

这将打印出如下内容:

 origin [email protected]:account-name/repo-name.git (fetch)
 origin [email protected]:account-name/repo-name.git (push)
  1. Remove the remote from your local git repo:

    git remote rm origin

  2. Add the remote back to your local repo:

    git remote add origin [email protected]:account-name/repo-name.git

  1. 从本地 git 存储库中删除遥控器:

    git remote rm origin

  2. 将远程添加回您的本地存储库:

    git remote add origin [email protected]:account-name/repo-name.git

回答by akansh tayal

Running command git update-ref -d refs/heads/origin/branchfixed it.

运行命令git update-ref -d refs/heads/origin/branch修复了它。

回答by FrankMonza

I fixed this by doing the following

我通过执行以下操作解决了这个问题

git branch --unset-upstream
rm .git/refs/remotes/origin/{branch}
git gc --prune=now
git branch --set-upstream-to=origin/{branch} {branch}
#or git push --set-upstream origin {branch}
git pull

This assuming that your local and remote branches are aligned and you are just getting the refs error as non fatal.

这假设您的本地和远程分支是对齐的,并且您只是将 refs 错误视为非致命错误。

回答by George Armstrong

I had this issue because I was on a branch that had a similar name to an upstream branch. i.e. the upstream branch was called example-branchand my local branch was called example-branch/backend. The solution was changing the name of my local branch like so:

我遇到这个问题是因为我在一个与上游分支名称相似的分支上。即上游分支被调用example-branch,我的本地分支被调用example-branch/backend。解决方案是像这样更改我本地分支的名称:

git branch -m <new name goes here>

回答by WolfTail

This is probably resolved by now. But here is what worked for me.

这可能现在已经解决了。但这是对我有用的。

  1. Location:

    • If locked repository is on the server-side:

      1. ssh to your git repository on the server.
      2. Login as user which has permissions to modify the repository and navigate to the repository on your server.
    • If locked repository is local only:

      1. Open the git console and navigate to the repository directory.
      2. Run this command:

        git update-server-info
        
  2. Fix the permissions on your (remote or/and local) repository if you have to. In my case I had to chmodto 777and chownto apache:apache

  3. Try to push again from the local repository:

    git push
    
  1. 地点:

    • 如果锁定的存储库在服务器端:

      1. ssh 到服务器上的 git 存储库。
      2. 以有权修改存储库并导航到您服务器上的存储库的用户身份登录。
    • 如果锁定的存储库仅在本地:

      1. 打开 git 控制台并导航到存储库目录。
      2. 运行此命令:

        git update-server-info
        
  2. 如果需要,请修复(远程或/和本地)存储库的权限。在我而言,我不得不chmod777chownapache:apache

  3. 尝试从本地存储库再次推送:

    git push
    

回答by emirc

What worked for me was:

对我有用的是:

  1. Remove .git/logs/refs/remotes/origin/branch
  2. Remove .git/refs/remotes/origin/branch
  3. Run git gc --prune=now
  1. 消除 .git/logs/refs/remotes/origin/branch
  2. 消除 .git/refs/remotes/origin/branch
  3. git gc --prune=now

回答by schmunk

This is how it works for me.

这就是它对我的工作方式。

  1. look up the Apache DAV lock file on your server (e.g. /var/lock/apache2/DAVlock)
  2. delete it
  3. recreate it with write permissions for the webserver
  4. restart the webserver
  1. 在您的服务器上查找 Apache DAV 锁定文件(例如 /var/lock/apache2/DAVlock)
  2. 删除它
  3. 使用网络服务器的写权限重新创建它
  4. 重新启动网络服务器

Even faster alternative:

更快的替代方案:

  1. look up the Apache DAV lock file on your server (e.g. /var/lock/apache2/DAVlock)
  2. Empty the file: cat /dev/null > /var/lock/apache2/DAVlock
  3. restart the webserver
  1. 在您的服务器上查找 Apache DAV 锁定文件(例如 /var/lock/apache2/DAVlock)
  2. 清空文件: cat /dev/null > /var/lock/apache2/DAVlock
  3. 重新启动网络服务器

回答by Josh

This sounds like a permissions issue - is it possible you had two windows open, executing with separate rights? Perhaps check ownership of the .git folder.

这听起来像是一个权限问题 - 是否有可能你打开了两个窗口,以不同的权限执行?也许检查 .git 文件夹的所有权。

Perhaps check to see if there is an outstanding file lock open, maybe use lsof to check, or the equivalent for your OS.

也许检查是否有一个未完成的文件锁打开,也许使用 lsof 来检查,或者您的操作系统的等效项。