【问题标题】:Git push error, head of distant repo is behind localGit推送错误,远程仓库负责人落后于本地
【发布时间】:2015-11-12 12:34:50
【问题描述】:

我的项目在 gitlab 上有一个 repo。我首先在 Windows 上提交并推送这个项目。在 ubuntu 上创建 VM 并复制粘贴我的项目文件夹后。我在 ubuntu 上继续我的项目,并且我确实提交了(没有推送)。我不再使用我的 Windows 项目。现在,当我想推送项目(ubuntu)时出现错误。我认为我有冲突和合并问题。 我如何在回购中push我的项目。我尝试pullfetch,但没有。

错误是:

! [rejected]        master -> master (non-fast-forward)
impossible to push references to 'repo'
tip: The updates were rejected because the head of the current branch is behind its remote peer. Integrate remote changes (eg 'git pull ...') before pushing again.

之后,当我执行 git pull origin master 时,我与许多文件发生了很多冲突。

你能帮帮我吗?

【问题讨论】:

  • 你不应该复制工作副本,你应该从 gitlab 克隆 repo。

标签: git github gitlab


【解决方案1】:

您应该执行git pull 并解决冲突文件。打开每一个,修复它,然后git add它。你会发现这样的冲突行:

对所有冲突文件执行此操作后,测试您的代码并运行git commit 以进行合并。之后你就可以推送了。

【讨论】:

    【解决方案2】:

    git 不允许您使用 pushpullfetch,因为您复制粘贴了整个目录。这也复制了 git 在git init 上创建的.git 文件夹。删除 .git 文件夹,然后使用 git init 重新初始化 git 存储库。

    这将根据新路径创建一个新的.git 指向。

    【讨论】:

      【解决方案3】:

      git pull 上,git 会合并冲突文件,你需要解决冲突并commit再次在 git 上推送 (git push origin master) 更新的代码。

      有关更多信息,请查看此链接: rejected master -> master (non-fast-forward)

      【讨论】:

        猜你喜欢
        • 2013-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-10
        • 2015-08-29
        • 2014-12-22
        • 2020-01-03
        • 1970-01-01
        相关资源
        最近更新 更多