“您的分支比 'origin/remote-branch' 领先 37 次提交。”合并后

'Your branch is ahead of 'origin/remote-branch' by 37 commit.' after merge

我已经完成了以下步骤:

>git checkout remote-branch-test
>git pull
>git checkout remote-branch
>git pull
>git merge remote-branch-test
Automatic merge failed; fix conflicts and then commit the result.

解决了冲突

>git add .
>git commit
>git push origin remote-branch
**! [remote rejected]   remote-branch -> remote-branch (you are not allowed to upload merges)
error: failed to push some refs to ....

当我在远程服务器上执行 git 状态时

>git status
On branch remote-branch
Your branch is ahead of 'origin/remote-branch' by 37 commits.
  (use "git push" to publish your local commits)

我无法将更改推送到远程

我在这里缺少什么?

这里有几点需要注意。 :

[remote rejected] ... you are not allowed to upload merges

这告诉我们您的“远程”——您要向其发送提交的另一个 Git——只是禁止所有合并提交,期间。

但是,该特定错误消息不是来自 Git 或 GitHub,而是来自 Gerrit。请参阅此处 Gerrit: remote rejected (you are not allowed to upload merges) even though I allowed "Push merge commit" for example. This implies that you're not using GitHub for your pushes. Hence the tag is probably inappropriate. And, since Gerrit adds its own layer of stuff atop Git, the tag may be inappropriate too. I added ,但您应确保这些标签正确并删除任何不合适的标签。

最后,一个合并添加很多提交是正常的:合并提交有两个父项,因此向某个分支添加一个合并提交 B 通常会添加 N+1 个提交到 B,其中 N 是可以从正在合并的提交中访问但不能从 B 中访问的提交数合并前的自身。因此,您的合并合并了现有的 36 次提交,加上合并本身,总共 37 次提交。

按照以下步骤解决问题:

git fetch

git checkout origin/remote-branch

git merge --squash origin/remote-branch-test

git commit

git push origin HEAD:refs/for/remote-branch