美文网首页
Git 常见问题

Git 常见问题

作者: MrTricker | 来源:发表于2019-05-14 13:36 被阅读0次

    git pull 拉去远程库代码到本地,提示错误 refusing to merge unrelated histories

    $ git pull
    ...
    fatal: refusing to merge unrelated histories
    

    字面理解:拒绝合并,与历史记录无关。
    git 认为远程库与你的本地代码,相关性太小。

    解决方法:
    强制 git 允许合并与本地无关的远程代码库。

    $ git pull --allow-unrelated-histories
    

    git push 推送本地代码到远程仓库,错误提示 failed to push some refs to 'https://github.com/repository/example.git'

    $ git push
    ...
    error: failed to push some refs to 'https://github.com/repository/example.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.
    

    字面理解:推送失败,远程库含有本地库没有的内容。
    多人合作的时候,本地的代码想要 push 到远程库,需要先把远程库的代码 pull 到本地。养成 push 前,先 pull 的习惯。

    解决方法:
    Pull before push, make it a habit.

    相关文章

      网友评论

          本文标题:Git 常见问题

          本文链接:https://www.haomeiwen.com/subject/ctrsaqtx.html