Git 本地推送远程失败 non-fast-forward

2年前 (2022) 程序员胖胖胖虎阿
203 0 0

To github.com:Yee-Q/yeexang-community.git
 ! [rejected]        dev -> dev (non-fast-forward)
error: failed to push some refs to 'git@github.com:Yee-Q/yeexang-community.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.

错误提示如上,本地项目向远程推送时,提示远程 non-fast-forward,即时本地比远程领先,推送前必须先合并,Git 也给出提示了,要我们先 git pull

There is no tracking information for the current branch

这是因为没有指定本地分支与远程分支的关联,可以使用

git pull origin dev

如果希望一劳永逸,可以使用

git branch --set-upstream-to=origin/dev

fatal: refusing to merge unrelated histories

执行 pull 操作时,如果出现这个错误,是由于本地仓库和远程仓库有不同的开始点,也就是两个仓库没有共同的 commit 点而出现的无法提交。这里我们需要用到 --allow-unrelated-histories,也就是我们的 pull 命令改为下面这样的:

git pull --allow-unrelated-histories

fix conflicts and then commit the result

pull 操作会自动进行合并,但产生了冲突。一般会有提示是哪个文件产生冲突,找到对应的文件进行修改,再提交一次就行了

版权声明:程序员胖胖胖虎阿 发表于 2022年10月5日 下午4:40。
转载请注明:Git 本地推送远程失败 non-fast-forward | 胖虎的工具箱-编程导航

相关文章

暂无评论

暂无评论...