在公司内网的github页面中直接删除了几个历史分支,回到自己的单机开发环境,git pull和git fetch之后,使用git branch -a命令查看,依然能够看到已经删除的分支,但无法checkout,使用命令git branch -d可以删除本地分支,但无法push,每次git push --delete origin时直接提示错误:
error: unable to delete 'origin/*****': remote ref does not exist
结果就是远程分支已经不存在,本地git缓存仍然显示服务器端存在已删除的分支,因为不是通过正常的git分支删除指令操作的,导致git服务器端与开发端之间的分支数据无法保持一致,又因服务器端确实删除了分支,本地缓存无法通过git pull或git fetch指令同步,结果就是上面讲的那样了。
解决方案
使用命令git fetch -p可以将最新的远端分支信息同步下来,并把远端已经不存在、但单机环境依然存在的分支信息清理掉。具体可使用git help fetch查看对应的说明
-p, --prune
Before fetching, remove any remote-tracking references that no longer exist on the remote. Tags are not subject to pruning if they are fetched only
because of the default tag auto-following or due to a --tags option. However, if tags are fetched due to an explicit refspec (either on the command
line or in the remote configuration, for example if the remote was cloned with the --mirror option), then they are also subject to pruning.
评论已关闭!