Updates were rejected because the tip of your current branch is behind

最近本地一个flutter项目因为当时使用可视化创建的时候出了一些问题,但是起初没有注意,后来因为需要新增一个语音插件,需要修改原生android MainActivity.java,才发现这个目录根本不存在,于是重新创建一个项目将原来那个项目文件拷入,等修改好后再使用git 连接原来那个项目的github仓库进行代码推送,发现老是提示如下错误


	$ git push -u origin master
	To https://github.com/dengxiaoning/flutter-trip.git
	 ! [rejected]        master -> master (non-fast-forward)
	error: failed to push some refs to 'https://github.com/dengxiaoning/flutter-trip.git'
	hint: Updates were rejected because the tip of your current branch is behind
	hint: its remote counterpart. Integrate the remote changes (e.g.
	hint: 'git pull ...') before pushing again.
	hint: See the 'Note about fast-forwards' in 'git push --help' for details.


【注意】我们可以增加参数 --rebase进行拉取将本地与远程合并,但是拉取后本地代码需要手动修改冲突

git pull origin master  --rebase

然后又使用pull 仓库代码拉取合并,但是推送任然失败,看有朋友说需要 增加 -f 进行强制拉取,但是试过也没用,最后反过来想来过强制推送看得行不


	$ git push -f origin master
	Counting objects: 173, done.
	Delta compression using up to 4 threads.
	Compressing objects: 100% (130/130), done.
	Writing objects: 100% (173/173), 1.66 MiB | 5.73 MiB/s, done.
	Total 173 (delta 9), reused 38 (delta 4)
	remote: Resolving deltas: 100% (9/9), done.
	To https://github.com/dengxiaoning/flutter-trip.git
	 + d137bd8...0208d12 master -> master (forced update)

一试咦还OK了,不错记录记录。

【注意】在协调时慎用,该参数-f会使用本地项目完全替换掉原仓库的项目,如果本地项目不能保证比远程仓库的完整切勿使用,否则追悔莫及

看看官方介绍


	-f--force
	Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. Also, when --force-with-lease option is used, the command refuses to update a remote ref whose current value does not match what is expected.
	
	
	This flag disables these checks, and can cause the remote repository to lose commits; use it with care.
	
	
	Note that --force applies to all the refs that are pushed, hence using it with push.default set to matching or with multiple push destinations configured with remote.*.push may overwrite refs other than the current branch (including local refs that are strictly behind their remote counterpart). To force a push to only one branch, use a + in front of the refspec to push (e.g git push origin +master to force a push to the master branch). See the <refspec>... section above for details.


【个人建议】我觉得最好的办法还是将自己本地修改的项目拷贝一份,然后新建项目目录重新拉取远程仓库代码,最后用本地修改的文件覆盖刚拉取的代码即可(前提还是在你修改期间,其他同事未有提交)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奔跑的痕迹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值