Skip to main content

此版本的 GitHub Enterprise 已停止服务 2022-10-12. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

处理非快进错误

有时,Git � 法在不丢失提交的情况下对远程仓库进行更改。 发生此情况时,推送会被拒绝。

如果其他人已推送与您相同的分支,Git 将� 法推送您的更改:

$ git push origin main
> To https://hostname/USERNAME/REPOSITORY.git
>  ! [rejected]        main -> main (non-fast-forward)
> error: failed to push some refs to 'https://hostname/USERNAME/REPOSITORY.git'
> To prevent you from losing history, non-fast-forward updates were rejected
> Merge the remote changes (e.g. 'git pull') before pushing again.  See the
> 'Note about fast-forwards' section of 'git push --help' for details.

可以通过提取和合并远程分支上所做的更改以及本地所做的更改来解决此问题:

$ git fetch origin
# Fetches updates made to an online repository
$ git merge origin YOUR_BRANCH_NAME
# Merges updates made online with your local work

或者,只需使用 git pull 一次执行这两个命令:

$ git pull origin YOUR_BRANCH_NAME
# Grabs online updates and merges them with your local work