git push origin master
显示错误
无法将一些引用推送到 '
git@github.com:xyz/abc.git'
为了防止您丢失历史记录,非快进更新被拒绝 在再次推送之前,请合并远程更改。请参阅 'git push --help
' 中的“有关快进”的注释以获取详细信息。
这是什么?如何恢复?
请查看GitHub帮助页面中的“推送分支”章节:
处理“non-fast-forward”错误
偶尔在推送时可能会遇到此错误:
$ git push origin master
To ../remote/
! [rejected] master -> master (non-fast forward)
error: failed to push some refs to '../remote/'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again. See the 'non-fast forward'
section of 'git push --help' for details.
如评论中Michael Mrozek所述,关于git push
的"快进提示"注释,还有更详细的内容。
$git push --force
非常重要:如果您所在的分支(想要合并的分支)和上游分支的名称不同,也可能会发生这种情况。此时工作流程可能如下:
git pull --rebase # to retrieve upstream changes, replay yours on top
git push --dry-run --verbose origin HEAD:master # always good idea: dry-runs..
git push origin HEAD:master # actually push current branch head (non-master) to upstream master
先拉取再推送
使用命令 git pull origin 任意分支名
如果你遇到了这个错误,而你的.git/config文件是正确的,那么请按照以下步骤进行操作(这是在git仓库中处理子模块时常见的问题-请从子模块目录中执行以下操作)
git push origin master <========== On "mybranch"
git checkout master <========== Switch to the branch you want to push to
git pull origin master <========== Get latest from remote repository
git pull origin mybranch <========== Merge in changes from "mybranch"
======== Resolve any issues ========
git push origin master <========== Push the merged changes