【问题标题】:Failed to push error when trying to push to Bitbucket尝试推送到 Bitbucket 时无法推送错误
【发布时间】:2019-07-22 12:43:43
【问题描述】:

当我尝试推送到 Bitbucket 时,我不断收到以下错误。我以前工作得很好,但它就停止工作了。

谁能帮我理解这是什么意思以及如何解决它?

Pushing to https://x-token-auth@bitbucket.org/UserName/project-name.git
To https://bitbucket.org/UserName/project-name.git
 = [up to date]      Redesign -> Redesign
 = [up to date]      Version4.0 -> Version4.0
 = [up to date]      version2.0 -> version2.0
 = [up to date]      version3.0 -> version3.0
 = [up to date]      version3.2 -> version3.2
 = [up to date]      version4.1 -> version4.1
 = [up to date]      version5.0.3+cocoapods-firebase -> version5.0.3+cocoapods-firebase
 = [up to date]      version5.1 -> version5.1
 = [up to date]      version5.2 -> version5.2
 = [up to date]      version5.3 -> version5.3
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://x-token-auth@bitbucket.org/UserName/project-name.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

仅供参考 - 我不确定如何按照错误中的建议使用 git pull。另外,我使用 git-tower 作为我的 git GUI。

【问题讨论】:

  • Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. ... 按照错误消息中包含的建议并执行git pull(或者可能是git pull --rebase)。
  • 另外,git merge origin/mater 也可以使用,因为 refs 已经更新
  • pull 在消息中基本上是fetch+merge。 Git 会阻止您推送到包含比本地更新版本的分支的远程。这将违反所有版本控制方法...
  • 当您尝试git pull 时会发生以下两种情况之一。如果您的本地更改与上游的更改无关,那么拉取将成功,您的工作目录和阶段基本相同。如果 Git 不能 执行拉取操作,那么您可能会看到一条错误消息,告诉您提交或存储本地工作,因为拉取操作会覆盖该工作。所以,在这种情况下,你必须先 stash 或 commit,然后再 pull。
  • 是的,你应该pull。让我把它写下来作为给你的正式答案。

标签: git bitbucket git-tower


【解决方案1】:

原因: 发生错误是因为remote 拥有比local 更新的master 版本。在这种情况下,git 禁止推送到分支,因为 - 将合并什么以及如何以及由谁解决冲突?总得有人负责,存储库不能单独完成这项工作。

Git 强制你首先 pull - pull 相当于 fetch+merge - 所以你将最新版本的代码收集到你的 local 并通过这样做继承合并的责任您的代码并解决您通过编写代码创建的合并冲突。否则,可以将它们卸载到remote 并留下一个没有所有者的烂摊子。

做什么: git pull。您将收到一条消息,要求您进行合并。如果发生合并冲突,您将被要求使用您选择的任何工具来解决它(我想在您的情况下是 git tower)。

之后,可以再次进行快进推送,直到有人再次推送到 master 并且分支再次拥有比您的 local 更新的通用代码库版本。

如何绕过它:...(部分)...在 Bitbucket 和 Github 上,您可以部署限制以推送到某些分支。这被称为“保护分支”。通过这样做,您可以禁止所有人推送到受保护的分支并在白名单的基础上继续进行。您可以定义推送限制,例如此分支上没有合并提交,合并前的强制拉取请求等。这将阻止人们随机推送到生产分支并排除问题的主要来源。

【讨论】:

  • 感谢您的解释。这里有趣的是,这是一个私人存储库,我是唯一一个在单台计算机上工作的人。换句话说,我不确定远程分支如何更新,因为没有其他人进行更改。
  • 也许你推错了分支?您可以使用图形历史来查找。
  • 我只有master分支。
  • 奇怪的是,这种情况下的拉取请求给出了“致命:拒绝合并不相关的历史”错误。另一个答案使它起作用。
  • 您好,我遇到了同样的问题。我是唯一一个在我的远程存储库上工作的人。一切正常,突然间我不能再推了。 git push origin master 返回fatal: the remote end hung up unexpectedly fatal: the remote end hung up unexpectedly error: failed to push some refs to... git pull已经是最新的。 有什么想法/原因为什么突然出现这个错误,而我是唯一一个在我的存储库上工作的人?谢谢
【解决方案2】:

你可以试试git push -u origin master--force

【讨论】:

  • 无法弄清楚如何将项目推送到我制作的全新 bitbucket 存储库,可能是因为我在线删除了一个“演示”.gitignore 文件。这解决了它!虽然我仍然不知道“正确”的方法是什么,但它有效!感谢您分享这个答案。
猜你喜欢
  • 1970-01-01
  • 2018-06-16
  • 1970-01-01
  • 2018-11-10
  • 2019-03-18
  • 1970-01-01
  • 1970-01-01
  • 2016-03-18
  • 2013-12-31
相关资源
最近更新 更多