0


git push报错rejected:no-fast-forward

报错:

在这里插入图片描述

报错关键词:

  • non-fast-forward
  • your current branch is behind
  • the remote changes

即:不能快速前进、当前分支滞后、远端改变

原因:

这个分支下,别人提交了一些代码到远程仓库。对于这个改变,你没有拉取到本地,而你又添加了一下新代码。此时你push到远程仓库,检测到你之前从远程仓库拉取时仓库的状态,和现在仓库的状态不一样了。为了安全起见,push被拒绝。

报错中其实已经说明逻辑:the remote changes ⇒ your current branch is behind ⇒ non-fast-forward ⇒ push rejected

解决:

  • 抓取这个分支在远程仓库的更新到本地
git fetch origin Feature-9527
  • 与本地仓库合并
git merge origin FETCH_HEAD
  • 重定基,使提交历史趋于一条直线
git rebase origin FETCH_HEAD
  • 重新push即可成功
git push

在这里插入图片描述

Tip:

git pull 

等价于

git fetch + git merge xxx

但推荐后者。

git pull --rebase

等价于

git fetch + git rebase xxx

最后,push被拒绝时,看看问题,多半都是远程仓库改变了,而你没拉取更新且新加了代码。别上手就git push -f 或者git push --force。远程仓库被覆盖就尬住了

标签: git

本文转载自: https://blog.csdn.net/llg___/article/details/131432197
版权归原作者 -代号9527 所有, 如有侵权,请联系我们删除。

“git push报错rejected:no-fast-forward”的评论:

还没有评论