Git踩坑指南

最近入职了七牛云,因为安全性的原因,加入github上的开发小组必须开启二次验证,今天想上传一个新的demo代码,搞了半天老是说我账号密码不对,RSA也不行,经过多次重试并且之前也使用git,所以我确定我的操作没有错,问题就在账号的二次验证上,经过一番曲折,终于搞定了,所以决定写下一篇博客作为记录,也为了他人遇到此问题快速查找解决方式,避免浪费时间。此博客会不断更新,作为一个git错误解决方式的集锦。

一、github开启二次验证之后使用git无法push

当你开启github二次密码验证后,你就会发现你push的时候要你的账号密码,而你怎么输都输不对

shaolongfeis-MacBook-Pro:MyOpenGLDemo shaolongfei$ git push origin master
Username for 'https://github.com': s15603333319
Password for 'https://[email protected]': 
remote: Invalid username or password.

这就很让人抓狂,你反复的输入密码,修改密码,还是不对。因为你开启了二次验证,你这里就不能用密码登录了而是要用Personal access token作为密码登录,这个token在哪获取呢?

1.在网页上登录github

2.你的头像 -> Settings -> Developer settings -> Personal access tokens -> Generate new token

然后填写token的描述啊 权限范围什么的 最后生成token

这个token你最好记下来,以后就查看不了了,可以更新和删除重建,现在你就可以拿着这个token去在push的时候登录了,登陆一次后git会自己记下来,以后就不用你自己输了。

二、github二次验证如何设置短信验证

如果你相要在github的二次验证中设置短信验证,你会发现一个问题,它不提供中国手机号的验证,怎么办呢?这能难倒咱们这些搞技术的吗?

道理很简单啊,直接改下网页就好了

把它传值改掉就可以,页面显示其实没必要动

这样你就可以收到短信啦

三、git push出现错误: Updates were rejected because the remote contains work that you do

To https://github.com/s15603333319/AndroidOpenGL.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/s15603333319/AndroidOpenGL.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

这个问题出现的原因是本地仓库与线上仓库的内容不匹配,或者说本地相对于远程不是最新,可以先pull更新本地,再把自己的push上去。如果你确定没问题可以git push -f强行上传。

git pull origin master

四、git pull出现错误:refusing to merge unrelated histories

warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/s15603333319/AndroidOpenGL
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories

这个错误产生的原因是合并了两个不同的开始提交的仓库,git 觉得这两个仓库可能不是同一个,所以就报错。

如果你确认没提交错origin 可以使用git pull origin master --allow-unrelated-histories来告诉 git 允许不相关历史合并

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章