【问题标题】:error: failed to push some refs to 'https://github.com/XXXXXXXXX.com错误:未能将一些参考推送到'https://github.com/XXXXXXXXX.com
【发布时间】:2020-12-30 16:09:03
【问题描述】:
$ git push -u origin master
To https://github.com/XXXXXXXXX.com/FirstRepo.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/XXXXXXXXX.com/FirstRepo.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.

我今天第一次使用 github,我已经检查了其他答案,其中只有一个似乎有效,那就是使用 'git push origin master --force',但这样做是删除所有其他提交。谁能告诉我解决方案。

【问题讨论】:

  • 你先拉了吗?
  • 您可以执行 git pull 来获取远程更改,然后您的推送应该可以工作
  • 是的,我在推送之前这样做了,但它仍然给出了相同的提示。但是在提交期间它的显示如下“创建模式 100644 textfile.txt”
  • 如果您先使用git pull,听起来好像出了点问题。发布更多细节。显示您的步骤,显示输出,然后也许我们可以帮助您完成它。目前,任何人都能给出的最佳建议是“先使用git pull”,然后再推送。
  • 你可以试试这个帖子:stackoverflow.com/questions/24114676/…

标签: git github push git-push git-pull


【解决方案1】:

只需在终端中运行此代码即可。

git pull origin master --allow-unrelated-histories

或者如果你使用主分支运行这个代码

git pull origin main --allow-unrelated-histories

【讨论】:

    【解决方案2】:

    如果您的 local 分支在您的 remote 分支之后并且在其之上有一些提交,那么您可以通过运行以下命令来解决您的问题。

    $ git pull origin master --rebase
    $ git push origin master
    

    注意:如果你只运行git pull 而没有--rebase,那么它会添加一个你可能不想要的merge 提交。

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 2013-01-25
      • 2021-09-15
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 2021-08-07
      • 2021-03-26
      相关资源
      最近更新 更多