Git提交代碼及異常處理方法

Git提交代碼及異常處理方法

1.開始步驟

  • 第一步:首先在gitee.com上創(chuàng)建一個(gè)項(xiàng)目,與你本地項(xiàng)目同名
  • 第二步:在git bash 下操作

① git init 初始化本地倉(cāng)庫(kù)

② git add . 將當(dāng)前文件加入到倉(cāng)庫(kù)

③ git commit -m 'first commit' 第一次提交項(xiàng)目文件

④ git remote add origin https://gitee.com/null_948_8938/ayiol_auth.git 關(guān)聯(lián)遠(yuǎn)程倉(cāng)庫(kù),藍(lán)色為git項(xiàng)目URL

⑤ git push -u origin master 推送遠(yuǎn)程倉(cāng)庫(kù)

2.異常

  • error: failed to push some refs to 'https://gitee.com/null_948_8938/ayiol_auth.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.
    
    
    

    方法:報(bào)錯(cuò)因?yàn)檫h(yuǎn)程倉(cāng)庫(kù)與本地倉(cāng)庫(kù)文件不一致,使用git pull拉下遠(yuǎn)程代碼到本地

    git pull
    
  • warning: no common commits
    
    remote: Counting objects: 3, done.
    
    remote: Compressing objects: 100% (2/2), done.
    
    remote: Total 3 (delta 0), reused 0 (delta 0)
    
    Unpacking objects: 100% (3/3), done.
    
    From https://gitee.com/null_948_8938/ayiol_auth
    
    * [new branch] master -> origin/master
    
    There is no tracking information for the current branch.
    
    Please specify which branch you want to merge with.
    
    See git-pull(1) for details.
    
    git pull <remote> <branch>
    
    If you wish to set tracking information for this branch you can do so with:
    
    git branch --set-upstream-to=origin/<branch> master
    
    

    原因:報(bào)錯(cuò)原因是沒(méi)有指定本地master和遠(yuǎn)程origin/master的連接,

    執(zhí)行g(shù)it branch --set-upstream master origin/master,設(shè)置鏈接

    git branch --set-upstream master origin/master
    
  • fatal: the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead.
    
    

    原因:

    再次執(zhí)行:git pull origin master
    
    
  • fatal: refusing to merge unrelated histories 拒絕合并不相關(guān)的歷史
    

    原因:

    報(bào)錯(cuò)原因是本地倉(cāng)庫(kù)與遠(yuǎn)程倉(cāng)庫(kù)不同
    
    解決方案:
    
    git添加一句代碼,這句代碼是在git2.9.2版本發(fā)生的,最新版本需要添加 --allow-unrelated-histories,此代碼為忽略不相關(guān)歷史文件
    
    即:git pull origin master --allow-unrelated-histories
     
    重新git push origin master ,不在報(bào)錯(cuò),推送完成
    
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容