开发时我们可能会遇到要切换项目远程地址的情况,使用 git
工具进行切换的方式如下:
查看远程仓库:$ git remote -v
添加远程仓库:$ git remote add [name] [url]
删除远程仓库:$ git remote rm [name]
修改远程仓库名称: $ git rename [old name] [new name]
修改远程仓库:
$ git remote set-url --push [name] [newUrl]
$ git remote set-url --fetch [name] [newUrl]
例如:git remote add origin https://gitee.com/shay_cormac/vuex_todo.git
切换步骤:
- 使用
git remote -v
查看远程仓库地址 - 使用
git remote rm [name]
删除现在的远程地址 - 使用
git remote add [name] [url]
添加新的远程地址 - 使用
git remote -v
查看远程仓库地址
此时可以尝试拉取代码,尝试是否已经连接到远程地址
————————————————————————————————————————————
注意:
在切换地址后,有可能出现 ssh key 的报错
Offending ECDSA key in /c/Users/tiansi/.ssh/known_hosts:1
在/known_hosts中输入错误的ECDSA密钥,对应的行数是 第1行
我们根据路径找到 known_hosts 这个文件,就在 .ssh 秘钥相同的地方
打开 known_hosts 这个文件,找到第一行的 ip
使用命令 ssh-keygen -R [ip]
例如:ssh-keygen -R 175.6.23.194
$ ssh-keygen -R 175.6.23.194
# Host 175.6.23.194 found: line 1
/c/Users/tiansi/.ssh/known_hosts updated.
Original contents retained as /c/Users/tiansi/.ssh/known_hosts.old
输入命令后,将会提示找到对应信息并更新,原来的内容保留为 /.ssh/known_hosts.old
最后再拉取一次代码
$ git pull
The authenticity of host 'gitlab.fybdp.com (175.6.23.194)' can't be established.
ECDSA key fingerprint is SHA256:XhkznICEts6Q3AY+5UGqfY60mxZTLpnlduKr5nz+df4.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitlab.fybdp.com,175.6.23.194' (ECDSA) to the list o
f known hosts.
会提示是否确定建立连接
yes 建立连接
Warning 警告
警告:永久添加’175.6.23.194’ (ECDSA)到已知主机列表。
此时就完成了远程仓库的链接
————————————————————————————————————————————————
参考:
ssh登录错误ECDSA host key for ip has changed和Offending key for IP in /root/.ssh/known_hosts:1