git报错记录

353 阅读3分钟

GIT上传基本命令

git init # 1.将项目文件夹初始化为git仓库 git add . # 2.把文件添加到暂存区 git commit -m 'first commit' # 3.把文件提交到仓库,引号内为说明内容 git remote add origin 你的远程库地址 # 4.关联到远程库 git pull --rebase origin master # 5.获取远程库与本地同步合并 git push -u origin master # 6.把本地库的内容推送到远程

报错过程

报错分析(项目一)

branch

On branch master nothing to commit, working tree clean错误提示 在git commit 出现 no changes added to commit (use "git add" and/or "git commit -a") 在修改config文件中擅自添加了branch的设置 [branch "master"] remote = origin merge = refs/heads/master 解决: 提交代码时 , 先执行 git add 命令 将文件添加到 " 暂存区 " , 然后执行 git commit 命令 将文件提交到 " 版本库 " ;

$ git commit -m "check" On branch master Your branch is based on 'origin/master', but the upstream is gone.(use "git branch --unset-upstream" to fixup)nothing to commit, working tree clean 版本分支(我在config里面的分支是1中的branch)

port

ssh: connect to host github.com port 22: Connection refused这个错误提示的是连接github.com 当前的端口号不支持 unable to access 'https://github.com/xxxxx.git/': Failed to connect to github.com port 443 after 171033 ms: Couldn't connect to server这个是我之前的端口号22没成功,我改成了443 这个地方更正一下,我之前改成了ssh, 然后我后来又遇到了,就去翻了一下,给出的解决方案是git取消代理 git config --global --unset http.proxy

LF/CR

warning: LF will be replaced by CRLF the next time Git touches it(执行git add . 出现) 分析:CR/LF是不同操作系统上使用的换行符,Windows 上的编辑器会把行尾的换行(LF)字符转换成回车(CR)和换行(LF) window系统设置: git config --global core.autocrlf true

ref

fatal:failed to push some refs to 'xxxxx.git' 解决1: git pull origin master || git push origin master 解决2:(但是如果是上传的时候是分别上传两个项目的话,注意rebase) git pull --rebase 把服务端的代码拉下来 git status 检查状态 git rebase --abort//取消合并 git rease --continue //继续执行 git rebase --continue git push

git缓存问题

Enumerating objects: 118, done. Counting objects: 报错原因:git默认的缓存大小不足导致的(ps:我觉得可能是我不停地报错,导致我之前上传的项目不停地git add .)
看了一下网上的步骤 " git config --global http.postBuffer 20000000"

waring:TLS

waring:| TLS certificate verification has been disabled!
来自网上的教程:git bash: git config --global http.sslVerify true 这个我用的时候好像没有什么影响

git.png

总结

我的仓库陆陆续续传了两天才上传还有一个原因是因为,网络不好,我一直以为我的git有了好大的问题,比如我的远程连接SSH没有配置好,我改成了.git ;然后还有就是origin master 分支出了问题,又把新建分支重新合并,中间还有status查看每一步的状态是否是正确的。

这里放一个转载:记一次使用commit提交大文件无法推送到远程库解决问题过程及git rebase使用 - findmoon - 博客园 (cnblogs.com),以防万一,用来学习

新的错误来了,在新的项目里面

SSH

ssh: connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 检查SSH连接 ssh -T git@github.com 本人适用的方法:找C盘用户名下的 .ssh文件夹 ,文件夹新建config,不添加后缀,打开,输入 Host github.com User YourEmail(你的邮箱) Hostname ssh.github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa Port 443 继续执行 : ssh -T git@github.com 会有一个选择,The authenticity of host '[ssh.github.com]:443 ..... can't be established.RSA key fingerprint is....:...... Are you sure you want to continue connecting (yes/no)? 输入yes
出现这个代表成功: Hi Clare! You've successfully authenticated, but GitHub does not provide shell access.

git分支

在git pull 时出现 If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> master 输出的提示信息“git新建分支以后,需要远程分支关联” git branch --set-upstream-to=origin/remote_branch  your_branch 其中,origin/remote_branch是你本地分支对应的远程分支;your_branch是你当前的本地分支。eg: git branch --set-upstream-to=origin/main  main

远程分支关联 track

branch 'master' set up to track 'origin/master'. 首先我是按照网上的例子走了一遍 git add ,commit , pull origin master, 在pull origin master 出现一个提示: * branch master -> FETCH_HEAD Already up to date. 接着在push命令下$ git push -u origin master
出现了Everything up-to-date branch 'master' set up to track 'origin/master'. 于是我去查了一下参数-u(相当于让你本地的仓库和远程的仓库进行了关联) git push -u origin -all 代表将本地已存在的git项目的所有分支推送到远程仓库名为origin的仓库 git push -u origin main 只推送main到远程仓库

我尝试了一下"git push " 提示我'Everything up-to-date' 正常来说这里就显示没问题了,然后我刷新了我的github,发现还是没有我的代码 这个时候想起来自己建了一个分支,于是仓库名下的master 进行分支的切换,于是代码它出现了(我是大怨种)

继续新的报错,又一个新的尝试,我想看看还有什么报错

git init

Initialized empty Git repository in 初始化空储存库,查了一下,有篇博客是代表初始化成功; git status 查看一下 显示出untracked file 继续git init ,显示已经初始化过了

git pull

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> 1.直接指定远程master git pull origin master 出现'fatal: couldn't find remote ref master' 2.先指定本地master到远程的master 接着pull $ git branch --set-upstream-to=origin/master master 'fatal: the requested upstream branch 'origin/master' does not exist' 到此为止:没有解决 我又试了一下 git push --set-upstream origin master 出现了: Failed to connect to github.com port 443 after 171079 ms:Couldn't connect to server

本地没有master分支

git branch -a 查看分支 解决方法 :git checkout master 出现Already on 'master' ,Branch 'master' set up to track remote branch 'master' from 'origin'. 说明已经切换到 master 上。 再次输入 git branch -a 发现有本地分支 a : 查看所有分支; v: 每个分支的最后一个提交 vv:本地分支与远程分支的关联关系

连接被重置

fatal: unable to access 'https://github.com/xxxxx.git/': Recv failure: Connection was reset 不能进入git仓库,连接被重置了(我这里走了梯子) 我直接关了梯子 别的方法:找到电脑上的端口(ipconfig ping) 然后 git config --global http.proxy xxx.x.x.xxx

关于最后

我直接git push -u origin master 就是说还是分支的问题,没有本地分支连接远程分支导致的一系列问题 所以下次最后的git push 就不能只写"git push"