完整报错:
To https://gitee.com/xxxx/scalaxxxxx.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/xxxx/scalaxxxxx.git
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
"non-fast-forward" 在 Git 中表示非快速向前合并。在 Git 中,快速向前合并是指将一个分支的提交直接应用到另一个分支上,而不需要进行额外的合并操作。如果 Git 提示 "non-fast-forward",则表示当前分支的提交历史与目标分支的提交历史不兼容,无法直接进行快速向前合并。
这种情况通常发生在你试图将本地分支推送到远程仓库的分支时,而远程分支已经存在了新的提交,导致了分叉。解决这个问题的方法通常是先将远程仓库的变更拉取到本地,然后解决任何冲突,最后再进行推送。
执行以下命令:
git pull origin master --allow-unrelated-histories
-allow-unrelated-histories
选项来允许合并不相关的历史记录,这里通过命令行解决冲突比较不方便,能用idea处理最好。
正常流程:
git remote add origin https://你的仓库
git remote -v --查看
git add .
git commit -m "test commit 1"
git pull origin master --allow-unrelated-histories
git push origin master