当checkout遇见“fatal: reference is not a tree”的错误时,可能是因为非常规操作导致分支的HEAD文件时间早与主分支的HEAD文件时间。
使用touch命令将分支HEAD时间刷新即可。
#linux
touch .git/refs/heads/分支名
#windows powershell
Set-ItemProperty -Path .git\refs\heads\分支名 -Name CreationTime -Value (date)
Set-ItemProperty -Path .git\refs\heads\分支名 -Name LastWriteTime -Value (date)
Set-ItemProperty -Path .git\refs\heads\分支名 -Name LastAccessTime -Value (date)
然后就可以正常使用checkout切换分支了。