Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fatal: Reference has invalid format: 'refs/heads/master~'

Tags:

git

When I try any of these commands:

git branch
git branch -a
git pull
git log --pretty=format:"%C(yellow)%h%Cred%d\\ %Cblue[%cn]\\%Creset %s" --decorate --graph
git log --online --decorate --graph

I get the error

fatal: Reference has invalid format: 'refs/heads/master~'

But the following commands work:

git log --oneline --graph # removed --decorate
git log

Running

find ./ -iname "*conflict*"

doesn't return any results.

The output of find ./ -name "*master*" | grep "\./\.git" is

./.git/logs/refs/heads/master
./.git/logs/refs/heads/master~
./.git/logs/refs/remotes/origin/master
./.git/refs/heads/master
./.git/refs/heads/master~
./.git/refs/remotes/origin/master

Don't know if that helps, but I see master~ in there.

Any idea what might be wrong? What other info can I provide you with?

like image 621
trusktr Avatar asked Mar 01 '14 08:03

trusktr


Video Answer


1 Answers

It looks like some utility has created "backups" of the normal branch files (.git/refs/heads/...) with a trailing ~ character. This are not allowed branch names in Git as they would conflict with the suffix notation ...~N for obtaining ancestors.

Commands that don't need to query all refs (such as git log master without --decorate) are working but anything that tries to list all branches is choking on the invalid branch name.

Simply delete the file ./.git/refs/heads/master~ (after backing it up) and you should be good to go.

like image 140
CB Bailey Avatar answered Oct 22 '22 10:10

CB Bailey