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

后端 未结 24 1361
礼貌的吻别
礼貌的吻别 2020-11-30 15:58

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

git push origin master

Errors

相关标签:
24条回答
  • 2020-11-30 16:43

    You want to try doing:

    git gc --prune=now
    

    See https://www.kernel.org/pub/software/scm/git/docs/git-gc.html

    0 讨论(0)
  • 2020-11-30 16:44

    In my case after getting this message I did the checkout command and was given this message:

    Your branch is based on 'origin/myBranch', but the upstream is gone.
      (use "git branch --unset-upstream" to fixup)
    

    After running this command I was back to normal.

    0 讨论(0)
  • 2020-11-30 16:45

    In my case a branch was moved to a subdirectory and the directory was called as the branch. Git was confused by that. When I deleted the local branch (in SourceTree just with right click delete) everything worked as usual.

    0 讨论(0)
  • 2020-11-30 16:45

    I saw this error when trying to run git filter-branch to detach many subdirectories into a new, separate repository (as in this answer).

    I tried all of the above solutions and none of them worked. Eventually, I decided I didn't need to preserve my tags all that badly in the new branch and just ran:

    git remote remove origin
    git tag | xargs git tag -d
    git gc --prune=now
    git filter-branch --index-filter 'git rm --cached -qr --ignore-unmatch -- . && git reset -q $GIT_COMMIT -- apps/AAA/ libs/xxx' --prune-empty -- --all
    
    0 讨论(0)
  • 2020-11-30 16:45

    for me, removing .git/info/ref kick things going.There shouldn't be a ref file when git is not running. But in my case there were one for whatever reason and caused the problem.

    Removing the file will not remove any of your local commits or branches.

    0 讨论(0)
  • 2020-11-30 16:47

    In my case, it was connected with the branch name that I had already created.

    To fix the issue I've created a branch with the name that for certain shouldn't exist, like:

    git checkout -b some_unknown_branch
    

    Then I've cleared all my other branches(not active) because they were just unnecessary garbage.

    git branch | grep -v \* | grep -v master | xargs git branch -D
    

    and then renamed my current branch with the name that I've intended, like:

    git checkout -m my_desired_branch_name
    
    0 讨论(0)
提交回复
热议问题