【问题标题】:git - Updates were rejected because the remote contains work that you do hint: not have locally [duplicate]git - 更新被拒绝,因为远程包含您提示的工作:本地没有 [重复]
【发布时间】:2020-08-07 02:11:25
【问题描述】:
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.

嗨,我是 git 新手,所以我们正在办公室做一个项目,我们正在使用 bitbucket。 我已经提交并推送了一些代码行。 对同一个 PR,另一个人推送了他们的代码。 我怎样才能将他们的代码拉到我的本地仓库?

我没有用他们的代码更新我的代码,当我尝试推送我的代码时出现上述错误。 强制推送后,他们的提交被覆盖。

【问题讨论】:

标签: git github bitbucket


【解决方案1】:

切勿强迫任何事情,尤其是当您不知道自己在做什么时。也就是说,你要做的正确的事情是使用git pull [remote] [branch] 拉他们的工作,修复任何合并冲突,提交并推送你的代码。现在,你已经强制推送你的代码并且你朋友的提交在遥控器上不存在,你的朋友必须做同样的事情

  1. git pull [remote] [branch]
  2. 修复合并冲突。如果有的话,Git 会警告你
  3. 如果与git commit 存在任何合并冲突,请提交
  4. git push [remote] [branch]

然后你可以做一个git pull [remote] [branch],一切都会同步。

【讨论】:

    【解决方案2】:

    您必须首先运行git pull 以下载并对存储库所做的更改并将其合并到存储库的本地克隆中。

    执行此操作时可能会遇到所谓的合并冲突。当您更改的某些代码不再存在或已在主存储库中更改时,就会发生这种情况。

    如果您遇到合并冲突,可以在这里找到帮助:

    https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts

    【讨论】:

    • git pull 从 master 或我签出的分支?
    • 您正在处理的分支。稍后你将你的分支合并到主分支中。
    猜你喜欢
    • 2022-01-08
    • 2013-08-22
    • 2021-07-30
    • 2018-03-29
    • 2018-08-16
    • 2016-11-08
    相关资源
    最近更新 更多