git

136 阅读1分钟

问题1:

git创建分支,本地看不到新建的分支

原因: 本地有缓存

git fetch //清理缓存
git branch -a  //查看分支

问题2:

撤回本地提交

git log 查看日志
git reset --soft 要回退到的版本号( 如果远程已经提交或者本地有新拉取的代码,强制撤回用hard)
git push origin 分支名称 --force 撤回远程仓库的提交

问题3:

git push出现如下报错 截屏2022-05-11 下午4.25.47.png

git pull

问题4:

自己的分支与主分支代码不一样,合并容易出现冲突,则先拉取主分支代码到自己本地

git pull origin ‘分支名字’

问题5:

无法连接github仓库

time git:(feature-style) git push
fatal: unable to access 'https://github.com/xxxxxxx.git/': Failed to connect to github.com port 443: Connection refused

大概率是 GitHub IP 无法访问导致的,通过设置代理🪜🪜可以解决此问题(🪜🪜)。

  • 全局代理
# 设置代理,http 和 https 都加上代理,代理到 http://127.0.0.1:1087 这个 vpn 本地 IP
git config --global http.proxy http://127.0.0.1:1087 
git config --global https.proxy http://127.0.0.1:1087

# 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy

# 查看代理
git config --global --get http.proxy
git config --global --get https.proxy

# 查看全局所有配置
git config --global --list
  • 本地代理
# 设置代理
git config --local http.proxy http://127.0.0.1:1087 
git config --local https.proxy http://127.0.0.1:1087

# 取消代理
git config --local --unset http.proxy
git config --local --unset https.proxy

参考文章:segmentfault.com/a/119000004…