【问题标题】:When pushing to remote repositories, what is the difference between these two rejection messages?推送到远程存储库时,这两个拒绝消息有什么区别?
【发布时间】:2022-11-21 02:30:52
【问题描述】:
  1. “远程包含您在本地没有的工作”
     ! [rejected]        feature/addition -> feature/addition (fetch first)
    error: failed to push some refs to 'github.com:<github_username>/<reponame>.git'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    
    1. “您当前分支的尖端在其远程分支的后面”
     ! [rejected]        feature/addition -> feature/addition (non-fast-forward)
    error: failed to push some refs to 'github.com:<github_username>/<reponame>.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 github push


【解决方案1】:

长话短说

  1. “远程包含你在本地没有的工作”意味着自上次获取以来远程发生了变化。

  2. “你当前分支的尖端在它的远程分支后面”意味着你已经从远程获取更改但还没有处理它们。

    更多详情

    它们是密切相关的消息:在这两种情况下,您的本地分支与远程分支不同步,您需要通过多种方式之一修复该问题:git pullgit pull --rebasegit fetch + 更新您的当地分支机构以您选择的方式。在第二种情况下,只需 git mergegit rebase 就足够了。

    区别在于:

    • 第一条消息说你甚至还没有从远程获取那些新的提交,你的本地 origin/&lt;branchname&gt; 远程跟踪分支落后了。通过仅在本地检查,您根本没有关于这些新提交的信息,并且 Git 告诉您“等一下,自从您上次查看以来,远程上发生了一些变化!”

      此时需要获取或拉取,然后您应该决定如何将您的工作与新的远程工作结合起来。

    • 第二条消息说你确实从远程获取,origin/&lt;branchname&gt; 与远程同步,但你没有将新提交合并到&lt;branchname&gt;。在这种情况下,您在本地拥有所有信息,但您还没有对其进行处理。

      也许你想合并、变基,或者如果你确定这是你需要做的,甚至可能想要强制推送。但实际上并不需要获取或拉取。

    正如@jmargolisvt 所说,git pull 将解决这两种情况,但我更喜欢的方法是git fetch,然后使用图形日志查看器检查新历史记录,然后通常是 rebase,很少是合并。 (我喜欢我的历史大部分是线性的,我倾向于对 PR 使用合并提交,但其他的不多。)

【讨论】:

    猜你喜欢
    • 2016-08-23
    • 2013-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多