本文记录了笔者在使用 github 过程中遇到的问题,仅供个人使用。
目录
- Could not resolve host
- local changes to the following files would be overwritten by merge
- TLS connection was non-properly terminated
- Updates were rejected because the remote contains work that you do not have locally.
Could not resolve host
【报错】在 Ubuntu 中执行 git clone
命令时,出现 Could not resolve host
报错:
先检查网络,保证发现本地可以访问 github 网站。
【原因】无法解析域名 github.com
【解决办法】打开 host 配置文件:
sudo vim /etc/hosts
键入 “i” 进入编辑模式,添加github.com域名:
140.82.114.4 github.com
添加后的配置文件如下:
编辑完成后键入 “Esc”,然后输入 :wq
保存并退出:
此时再执行 ping github.com
发现可 ping 通:
local changes to the following files would be overwritten by merge
【报错】在使用 git pull
指令拉取仓库代码时出现 error: Your local changes to the following files would be overwritten by merge: XXXXX. Please commit your changes or stash them before you merge. Aborting.
的报错:
【原因】队友修改了某个文件并提交到版本库中,不巧的是我在本地也修改了同一个,这时候直接拉取就会出现冲突了。
【解决办法】如果本地修改的内容无需保留,则可以撤销工作区中所有未提交的修改内容,将暂存区与工作区都退回到上一次版本:
git reset --hard
git pull
如果本地修改的内容不想被覆盖,则可以将所有未提交的修改保存至堆栈中,拉取代码后再恢复:
git stash
git pull
git stash pop
TLS connection was non-properly terminated
【报错】在 Ubuntu 中执行 git clone
命令出现 GnuTLS recv error (-110): The TLS connection was non-properly terminated.
报错:
【解决办法】执行 clone
指令前,先执行以下指令:
export GIT_TRACE_PACKET=1
export GIT_TRACE=1
export GIT_CURL_VERBOSE=1
然后即可成功执行 git clone
命令。
Updates were rejected because the remote contains work that you do not have locally.
【报错】在使用 git push
指令提交代码时出现 error: Your local changes to the following files would be overwritten by merge: XXXXX. Please commit your changes or stash them before you merge. Aborting.
的报错:
【原因】本地分支和远程分支不一致。
【解决办法】先从远程仓库拉取最新的代码到本地,再将本地的代码推送到远程仓库的 main 分支:
git pull origin main --allow-unrelated-histories
git push origin main