美文网首页
Git提交代码及异常处理方法

Git提交代码及异常处理方法

作者: Java小白笔记 | 来源:发表于2022-01-26 15:27 被阅读0次

Git提交代码及异常处理方法

1.开始步骤

  • 第一步:首先在gitee.com上创建一个项目,与你本地项目同名
  • 第二步:在git bash 下操作

① git init 初始化本地仓库

② git add . 将当前文件加入到仓库

③ git commit -m 'first commit' 第一次提交项目文件

④ git remote add origin https://gitee.com/null_948_8938/ayiol_auth.git 关联远程仓库,蓝色为git项目URL

⑤ git push -u origin master 推送远程仓库

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.
    
    
    

    方法:报错因为远程仓库与本地仓库文件不一致,使用git pull拉下远程代码到本地

    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
    
    

    原因:报错原因是没有指定本地master和远程origin/master的连接,

    执行git branch --set-upstream master origin/master,设置链接

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

    原因:

    再次执行:git pull origin master
    
    
  • fatal: refusing to merge unrelated histories 拒绝合并不相关的历史
    

    原因:

    报错原因是本地仓库与远程仓库不同
    
    解决方案:
    
    git添加一句代码,这句代码是在git2.9.2版本发生的,最新版本需要添加 --allow-unrelated-histories,此代码为忽略不相关历史文件
    
    即:git pull origin master --allow-unrelated-histories
     
    重新git push origin master ,不在报错,推送完成
    

相关文章

  • Git提交代码及异常处理方法

    Git提交代码及异常处理方法 1.开始步骤 第一步:首先在gitee.com上创建一个项目,与你本地项目同名第二步...

  • 日常用的git提交代码的方法

    日常用的git提交代码的方法 一、初始化本地仓库,提交代码,提交到远程git仓库 1、初始化代码仓库 git in...

  • git提交代码时的异常处理

    1. 解决pull/fetch/push时,出现"fatal: Out of memory, malloc fai...

  • 基于git的代码版本管理规范及流程-简版

    基于git的简单实用的版本管理规范及流程,包括:代码库的分布、人员角色的划分、代码提交合并流程、代码冲突处理、分支...

  • git 提交代码

    第一种方法:(本地代码没有更改) 第二种方法:(本地代码已经修改) git 提交 本地代码到主分支 git 提交 ...

  • Git Tag使用

    tag a、发布tag方法 1、git add →git commit →git push 提交代码 2、git...

  • git 冲突问题

    提交代码,远程提醒有冲突: 解决方法: 1 : git fetch 获取代码 2 : git rebase ori...

  • git清空所有记录

    git 清空所有commit记录方法 说明:例如将代码提交到git仓库,将一些敏感信息提交,所以需要删除提交记录以...

  • 如何优雅的撤销commit和add操作

    用Git的时候commit提交代码后,发现这一次commit的内容是有错误的,或者不想提交了,那么有两种处理方法:...

  • git 删除无用目录,添加忽略文件

    1.在已经提交的Git代码管理里删除不想提交的目录或文件 ***2 Git忽略规则及.gitignore规则不生效...

网友评论

      本文标题:Git提交代码及异常处理方法

      本文链接:https://www.haomeiwen.com/subject/ycunhrtx.html