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 允許不相關歷史合併

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