git 问题汇总
How to uncommit
In the simplest terms: git reset --soft comm_hash_id
,
comm_hash_id 通过 git log 查看,也可以使用 HEAD
,
HEAD^
来快捷代替
--soft
: uncommit changes, changes are left
staged (index). --mixed
(default):
uncommit + unstage changes, changes are left in
working tree. --hard
: uncommit + unstage +
delete changes, nothing left.
参考资料
- version control - What's the difference between git reset --mixed, --soft, and --hard? - Stack Overflow
- undo - How to uncommit my last commit in Git - Stack Overflow
使用 ssh 的方式进行 clone 或者 push 时报错
1 | ssh: connect to host github.com port 22: Connection refused |
或者
1 | repository access denied. |
原因:在没有配置 ssh 密钥的情况下,使用 ssh 协议克隆仓库是不可行的,
解决办法:
- 改用 https 协议的链接克隆仓库
- 配置 ssh 密钥之后再使用 ssh 协议
有时候 github 被屏蔽,也会有这种类似报错,ssh 被阻断了,挂梯子
Git 将默认分支由 master 改为了 main,导致报错
github 在 2020/10/1 宣布所有新库都将用中性词「main」命名,取代原来的「master」
最新 git 建仓库并习惯性使用 master 来 push 的时候,报错:
1 |
|
解决方法:
将分支 check out 到 master,然后 push
1
2git checkout -b master
git push origin master不指名当前分支,只说将 local red HEAD 推送到远端的 master
git push origin HEAD:master
参考资料
git push GnuTLS recv error (-110): The TLS 报错
this solution below worked for me
1 | apt-get install gnutls-bin |
go get/git LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
1 | git config --global --unset https.proxy |
git push require username password
A common cause is cloning using the default (HTTPS) instead of SSH. You can correct this by going to your repository, clicking "Clone or download", then clicking the "Use SSH" button above the URL field and updating the URL of your origin remote like this:
git remote set-url origin git@github.com:username/repo.git
You can check if you have added the remote as HTTPS or SSH using:
git remote -v
注意:clone 的时候使用 https 还是 ssh 是有区别的。 clone 自己的仓库用 ssh, clone 别人的仓库用 https,因为权限不同, clone 自己仓库的 https 版本如果 push 的话需要提供用户名和密码,而 git 现在版本不再支持该方式。
参考:github - Git push requires username and password - Stack Overflow
ssh 访问 github 超时
ssh: connect to host Build software better, together port 22: Connection timed out
在 fork 了别人的仓库,clone 到本地修改之后,push
不上去了,本来以为网络或者代理问题,但搞了半天都不行,最后解决了:
方法:Switching remote URLs from SSH to HTTPS,从 SSH 协议修改成了 HTTPS
协议