Git之常见异常收集

Push to origin /master was rejected



2   failed to push some refs to

描述:
$ git push -u origin master
To git@github.com:******/Demo.git
 ! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:******/Demo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决方案:
(1).使用强制push的方法:
$ git push -u origin master -f 
这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。
(2).push前先将远程repository修改pull下来
$ git pull origin master
$ git push -u origin master
(3).若不想merge远程和本地修改,可以先创建新的分支:
$ git branch [name]
然后push
$ git push -u origin [name]


fatal: refusing to merge unrelated histories

描述:这是从远程库pull项目,合并文件发生的异常
解决方案:在pull的时候添加  --allow-unrelated-histories。
git pull origin master ----allow-unrelated-histories

 error:src refspec master does not match any

描述:在push项目的时候,引发该异常。
原因分析: 目录中没有文件,空目录是不能提交上去的,获取没有add、commit文件直接进行push了。
解决方案:
$ touch README
$ git add README 
$ git commit -m 'first commit'
$ git push origin master

fatal: Authentication failed for 'https://github.com/ ...

描述: 使用的https提交,在用SourceTree提交代码时候发生错误,返回的错误提示说:
fatal: Authentication failed for 'https://github.com/ ...   
解决方案: 重新执行 Git  config命令配置用户名和邮箱即可:
$git config -–global user.name "xxx"   
$git config –-global user.email "xxx@xxx.com"
   

! [rejected] master -> master (fetch first)

描述: To git@git.oschina.net:yangzhi/hello.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@git.oschina.net:yangzhi/hello.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushin
hint: to the same ref. You may want to first merge the remote changes (e.g.
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决方案:
可以输入:$ git push -u origin master -f

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值