当前位置: 动力学知识库 > 问答 > 编程问答 >

github - git checkout failing because branch already exists

问题描述:

I am trying to checkout a branch that I was checking out with success in the past, and I can't check it out anymore. Here are the different messages I am getting. The easy solution would be to reset my folder, do a git init and git clone, but I do not want to reset my git folder as I set up things like git hooks (post-checkout, post-merge, etc). How could I get this to work again without resetting everything?

fatal: A branch named 'stage' already exists.

git fatal: reference is not a tree

error: refs/heads/stage does not point to a valid object!

fatal: bad object stage

网友答案:

In Git branch is simply a pointer. The pointer is to the SHA-1 of the current commit in the branch and this information is stored in the file you just deleted: .git/refs/heads/<your_branch_name>

If you wish to verify that your repository does not contains any more loose objects (dangaling) or un-reached branches check it with this:

git fsck --full
网友答案:

The way to solve this in a clean way is to delete your corrupted branch in .git/refs/heads/your_branch_name.

分享给朋友:
您可能感兴趣的文章:
随机阅读: