Git - 總結在使用 Git 踩過的坑


 

前言

總結在使用 Git 遇到的問題 

 

問題(一)

如圖所示

 

 

 

Push failed Enumerating objects: 727, done. Delta compression using up to 12 threads RPC failed; curl 18 transfer closed with outstanding read data remaining the remote end hung up unexpectedly Total 727 (delta 60), reused 0 (delta 0), pack-reused 0 the remote end hung up unexpectedly

 

原因分析

git 有兩種拉代碼的方式,一個是 HTTP,另一個是 ssh。git 的 HTTP 底層是通過 curl 的。HTTP 底層基於 TCP,而 TCP 協議的實現是有緩沖區的。 所以這個報錯大致意思就是說,連接已經關閉,但是此時有未處理完的數據;

因為git項目或者文件太大造成的錯誤,而緩沖區太小,所以導致這個錯誤

解決方案

step1:查看git的配置

git config -l

 

 

 

step2:加大緩沖區大小(http.postBuffer的參數)

 

增大緩沖區大小。 
(1)切到 git 項目目錄后,執行如下命令,

// 524288000 的單位代表 B,524288000B 也就是 500MB。
// 這個值的大小,可自行酌情設置。
git config –
-global http.postBuffer 524288000

git config http.postBuffer 524288000

然后查看是否設置成功,

git config –l | grep postbuffer
 

如果以上都不行,使用以下方法:

配置如下:

$ git config --global http.postBuffer 24288000

$ git config --list

 

問題(二)

如圖所示

 

 

Push rejected 
Push master to autoShell/master was rejected by remote

 

原因分析

這個分支受保護不允許提交,意思是我的權限太低,由於這個是master分支,所以dev權限不允許,找管理員授權吧,或者另外拉dev分支后在去合並到master

 

解決方案

git remote add origin git@github.com:emeil/autoShell.git
// 添加遠程版本庫

git branch -M main // 修改分支名 M強制修改 若與其他分支有沖突也會創建(慎用)

git push -u origin main

 

問題(三)

error: failed to push some refs to 'github.com:email/autoShell.git'

 

原因分析

當我們在github版本庫中發現一個問題后,你在github上對它進行了在線的修改;或者你直接在github上的某個庫中添加readme文件或者其他什么文件,但是沒有對本地庫進行同步。這個時候當你再次有commit想要從本地庫提交到遠程的github庫中時就會出現push失敗的問題。

解決方案

這個問題是因為遠程庫與本地庫不一致造成的,那么我們把遠程庫同步到本地庫就可以了。

git pull --rebase origin master

執行以上命令

 

 

問題(四)

 

 

fatal: couldn't find remote ref master

 

原因分析

新建的項目,pull的時候出現這錯誤,說白了就是這個項目還沒有文件,直接把本地修改的上傳就可以了,不需要拉了

解決方案

(1)檢查本地GIT的配置:檢查本地的用戶名和郵箱是否填寫正確
查看
$ git config user.name
$ git config user.email

修改
$ git config --global user.name "你的中文名"
$ git config --global user.email "郵箱"

(2)檢查遠程倉庫配置:如果遠程倉庫信息有誤,則刪除本地倉庫配置,並且設置相關地址

查看
$ git remote -v
$ git remote rm origin
$ git remote add origin XXXX // XXXX 指的是 git@github.com:emeil/autoShell.git


(3)還是不行的話可以找到文件路徑下 git文件所在,打開config文件,刪除[remote “origin”] 下信息。重復1,2步驟。
 


 

問題(五)

 

 

Can't finish GitHub sharing process
Successfully created project 'autoShellScript' on GitHub, but initial push failed: Enumerating objects: 727, done. Delta compression using up to 12 threads Total 727 (delta 61), reused 0 (delta 0), pack-reused 0 remote: warning: File kubernetes/kube-scheduler/kube-scheduler is 54.54 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB remote: warning: File kubernetes/kubectl/kubectl is 54.70 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com. remote: error: Trace: 1ff0549417dca974ee15fac5973ef800677da53a6376c2dec9f827be0627bcd6 remote: error: See http://git.io/iEPt8g for more information. remote: error: File kubernetes/kubelet/kubelet is 168.56 MB; this exceeds GitHub's file size limit of 100.00 MB remote: error: File kubernetes/kube-apiserver/kube-apiserver is 183.85 MB; this exceeds GitHub's file size limit of 100.00 MB remote: error: File kubernetes/kube-controller-manager/kube-controller-manager is 155.40 MB; this exceeds GitHub's file size limit of 100.00 MB failed to push some refs to 'https://github.com/lewyuejian/autoShellScript.git'

 

 問題(六)

# 執行git push –u origin master命令報錯(不能讀取遠程倉庫)
fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

解決方案:

(1)本地用用戶名和郵箱和GitHub賬戶不一致的問題

git config --global user.name "xxxx"
git config --global user.email "xxxx@163.com"

# 然后再執行git push –u origin master

(2)沒有設置過ssh key

 

 

命令鏈接 https://www.cnblogs.com/mrzll/p/12049280.html


免責聲明!

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



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