git branch -d <BRANCH>: Fatal - Couldn't look up commit object for HEAD

匿名 (未验证) 提交于 2019-12-03 08:48:34

问题:

Say I am in a bare repository (a remote), if I try to delete a branch with git branch -d <branch_name> I get the following error:

fatal: Couldn't look up commit object for HEAD

Why? Is there a reason why I should be unable to delete branches from a bare repository?

回答1:

Make sure you use a capitol D in the command, in this case you would type git branch -D <branch_name>. Note that this will only delete the branch from your local computer

If you are trying to delete a remote branch, type git push origin :<branch_name> (remember to add the colon)



回答2:

To avoid this confusion you can use

"git push origin --delete branch_name"

this deletes remote branch not local branch.



回答3:

Find the file .git/refs/heads/branch_name in Windows Explorer and directly delete it.



回答4:

This only happens when the default branch (the branch HEAD in the bare repository folder is pointing to - usually master) doesn't exist locally. If it does exist - you would be able to delete the branch with branch -d even from a bare repository folder (-d assuming it was merged).

If you are working with git worktrees - issuing the command from the worktree may succeed (same condition regarding HEAD of the worktree should be met)



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!