遇到这种情况,应该在Windows全盘搜索 hosts 文件,该文件为Windows系统盘下某个名为/etc文件夹下,注意是Windows系统盘,并不是Git软件安装位置下的/etc文件夹。
找到该文件后,一般是不允许你做修改(系统盘文件夹做了权限设置),但是可以先把hosts文件拷贝到桌面打开做如下修改后再拷贝至原路径下。
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
# IP地址 域名,如下形式即可
192.168.1.1 gitlab.com
修改后可以在 cmd 窗口敲入如下命令进行测试,看看是否添加成功
即“ping 域名”
ping gitlab.com
出现正常连接结果则修改完成。