在實際項目中使用git推代碼踩過的坑


Git使用中出現的狀況:

BUG集錦:

  1. On branch dev nothing to commit, working tree clean

image-20200326231641747

說明在dev分支上,沒有什么提交,很干凈;

2.fatal:couldn't find remote ref devimage-20200326232442805

新建項目時,pull出現的報錯信息,說明項目還有有文件,時空的直接進行推代碼

3.git push -u origin devimage-20200326233752933

將代碼推至dev分支上

4.現有的代碼在dev分支上,將dev分支代碼合並到master分支上

4.1 git branch 查看現有分支

4.2 git checkout master 切換到master分支上

4.3 git pull 拉去代碼

4.4 git add . 提交代碼信息

4.5 git commit -m "*****" 合並dev分支代碼

4.6 git push. 推代碼

image-20200326235311045

5.error:src ref spec master does not match any. Error:failed to push some refs to

常見原因:

5.1 本地git長褲目錄下為空

5.2 本地倉庫add后沒有commit

5.3 git init錯誤

6. fatal:remote origin already exits

首先刪除:git remote rm origin

再繼續執行

7. Error:failed to push some refs to

​ 起初我們在遠端創建倉庫時,已經存在README文件和.gitignore文件,然后將本地關聯遠端,所以在本地推代碼至遠端,會報錯failed,因為兩端都有內容,卻沒有任何聯系,所以在拉取或者推代碼時,git總會讓你先拉取后推代碼,但是拉取卻是失敗的;

​ 方案:為了避免報錯,我們在遠端常見倉庫時,最好是創建一個空的倉庫,在github創建時會提示:

Skip this step if you're importing an existing repository(如果你想導入庫,請跳過此步驟)

This will let you immediately clone the repository to your computer(允許你將庫克隆到你的計算機上)

8. Error:pathspec 'master' did not match any file(s) known to git
9. fatal:refusing to merge unrelated histories

​ 因為遠程倉庫已經存在代碼記錄了,並且那部分代碼沒有和本地倉庫進行關聯,我們可以使用如下操作允許pull未關聯的遠程倉庫舊代碼;

​ 方案:git pull origin master --allow-unrelated-histories

10.please make sure you have the correct access rights and the repository exists

需要重新配置本地ssh密鑰


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM