当我试图将我的代码推送到GitHub时,我遇到了一些问题。
Pushing to git@github.com:519ebayproject/519ebayproject.git
To git@github.com:519ebayproject/519ebayproject.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:519ebayproject/519ebayproject.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
我还没有在存储库中推入任何东西,那么为什么我需要拉出一些东西呢?
有些人可能会遇到这个错误,因为Git不知道您要推哪个分支。
如果您的错误消息还包括
error: failed to push some refs to 'git@github.com:jkubicek/my_proj.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you did not intend to push that branch, you may want to
hint: specify branches to push or set the 'push.default' configuration
hint: variable to 'current' or 'upstream' to push only the current branch.
那么你可能想要遵循Jim Kubicek的提示,将Git配置为只推送当前分支,将默认分支设置为当前分支。
git config --global push.default current
如果您确定没有人对您的git存储库进行更改,并且您正在使用最新版本,那么git pull作为解决方案在您心中并没有意义……
然后可能发生了这样的事情,你使用git commit -amend
它允许您将阶段性更改与前一次提交结合起来,而不是将其作为一个全新的快照提交。它还可以用于简单地编辑前一个提交消息,而不更改其快照。
ATLASSIAN教程:重写历史
然而,如果你已经将提交推到GitHub,不建议执行git commit -amend,这是因为“修改不仅会改变最近的提交,它会完全替换它。”对Git来说,它看起来像一个全新的提交”,这意味着对你GitHub上的其他开发人员来说,历史看起来像a ->B->C,但对你来说,它看起来像a ->B->D,如果GitHub让你推送,其他人都必须手动修复他们的历史
这就是为什么您会得到错误消息的原因!master -> master(非快进),如果你知道没有人拉出你的最新更改,你可以使用git push -force,这将改变你的公共回购中的git历史记录。否则……你可以执行git pull,但我相信这将有相同的结果,因为你没有经过git commit -amend,它将创建一个新的提交(即:git pull后的git历史:a ->B->C->D)
有关更多详细信息:如何更改最新提交
您的分支应该在注意到最新合并的更改时立即包含它们,但是您还没有提取最新的更改。
git fetch
也许这就是所需要的。如果这不起作用,那么你可能需要:
git pull <sharedRepo> <branch> --rebase
如果您没有任何合并冲突,您应该能够成功地推动您的更改。
git push <forkedRepo> <branch>
如果您遇到合并冲突,您无法在GitHub中远程解决。您必须在本地解决它们,然后使用强制标签推动解决方案,因为合并冲突解决方案将更改历史记录。
git push <forkedRepo> <branch> -f