Fatal: the link is in the wrong format: 'refs / heads / master ~'

When I try to execute 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 an error

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

But the following commands work:

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

Launch

 find ./ -iname "*conflict*" 

does not return any results.

The output of find ./ -name "*master*" | grep "\./\.git" 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 

I don't know if this helps, but I see master~ there.

Any idea what could be wrong? What additional information can I provide you?

+7
git
source share
3 answers

It looks like some kind of utility has backed up regular branch files ( .git/refs/heads/... ) with the ~ symbol. This does not resolve branch names in Git, as they will contradict the suffix notation ...~N to get the ancestors.

Commands that do not need to request all links (for example, git log master without --decorate ) work, but everything that tries to list all branches suffocates on behalf of an invalid branch.

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

+13
source share

I think your .git / HEAD file has invalid content. Check this file, and if it has a tilde added to the content, delete it. For example, here in one of my repositories:

 $ cat .git/HEAD ref: refs/heads/master 

Some of the files in .git are pointers to other links like this. Git reads them, shares the contents, and uses this as an object reference to continue.

There may be a server-side error - so you should check this too.

+2
source share

Delete your editor's replacement / backup files

The files you discovered are not git-related - they are created by the editor when you open the file name without ~ .

Just delete them, and if you want to prevent this problem in the future, just configure your editor to not create paging / backup files in the same directory as the file you are editing.

+2
source share

All Articles