Skip to content

推送拒绝

错误信息

                ! [拒绝] 主要 -> 主要 (获取首先)
              

快速摘要

你的推送是拒绝因为 remote 分支有 newer 提交 — 你需要到拉取 and integrate 它们首先.

为什么发生

  • 某人 else pushed 提交到 remote 那个你 don't 有 locally

  • 你的局部分支是后面 remote 分支

  • Force 推送是禁用 on remote 分支 (e.g., 受保护 主要)

最小示例

✗ 错误代码
git push  # ! [rejected] main -> main (fetch first)
✓ 修复代码
git pull --rebase
git push  # now succeeds

remote 有提交你 don't 有 — git 拉取 --rebase integrates 它们首先, 然后 git 推送 succeeds.

如何诊断

  • 运行 git 状态 — 做它 say 你的分支是后面 remote?

  • 运行 git 获取 到 download remote 更改不使用合并

  • 检查 git log 原点/主要..主要 到 see 如何你的局部提交 differ

如何修复

  • 运行 git 拉取 (or git 拉取 --rebase) 到 integrate remote 更改

  • Resolve 任何合并 conflicts 那个 arise 从拉取

  • 运行 git 推送 再次之后拉取 succeeds

如何预防

  • 拉取之前你推送到 stay in sync 使用 remote

  • 推送频繁地 in 小 increments 到 avoid 大 divergences

相关资源

相关术语

相关课程

相关练习

← 返回语言