可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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)