git 问题解决总结

本文详细解析了在使用Git过程中常见的两个错误:非快速前进更新(non-fast-forward)及远程起源已存在。针对这两个问题,文章提供了具体的操作步骤和解决办法,帮助读者理解错误原因并学会如何处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 记录git 问题

1.git push 报错non-fast-forward


$ git push origin master  
To ../remote/  
 ! [rejected]        master -> master (non-fast forward)  
error: failed to push some refs to '../remote/'  
o prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'non-fast forward'
section of 'git push --help' for details.

  This error can be a bit overwhelming at first, do not fear. Simply put, git cannot make the change on the remote without losing commits, so it refuses the push. Usually this is caused by another user pushing to the same branch. You can remedy this by fetching and merging the remote branch, or using pull to perform both at once.

  In other cases this error is a result of destructive changes made locally by using commands like git commit --amend or git rebase. While you can override the remote by adding --force to the push command, you should only do so if you are absolutely certain this is what you want to do. Force-pushes can cause issues for other users that have fetched the remote branch, and is considered bad practice. When in doubt, don’t force-push.

解决方法:

//强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容
git push -f  origin master  

2.上传本地代码到公司gitlab 报错:
执行git remote add origin ssh://xxx/xxx/xxx.git
fatal: remote origin already exists.(报错远程起源已经存在。)

问题:上传的代码已经有远程源。

:~/Documents/openblt$ git remote -v
origin  https://github.com/feaser/openblt.git (fetch)

解决方法:

1、git remote rm origin
2、git remote add origin ssh://xxx/xxx/xxx.git
3、git push origin master
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值