美文网首页
git pull 拉取更新失败

git pull 拉取更新失败

作者: b77bb494e846 | 来源:发表于2018-12-24 16:37 被阅读0次

    首先感谢原博主
    https://blog.csdn.net/lddtime/article/details/77817317

    在git仓库中新建了一个仓库,想要把本地的项目传上去

    在项目中:

    git init
    git add .
    git commit "提交说明"
    

    连接远程主机:

    git remote add  origin  远程仓库地址
    

    push到远程仓库:

    git  push origin master
    
    MacBook-Pro:~/go/src/demo/open$ git push -u origin master
    To codehub.devcloud.huaweicloud.com:t00001/open.git
     ! [rejected]        master -> master (non-fast-forward)
    error: 推送一些引用到 'git@codehub.devcloud:Openxt00001/open.git' 失败
    提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。
    提示:再次推送前,先与远程变更合并(如 'git pull ...')。详见
    提示:'git push --help' 中的 'Note about fast-forwards' 小节。
    

    提示先拉取更新

    MacBook-Pro:~/go/src/demo/open$ git pull origin master
    来自 codehub.devcloud.enxt00001/open
     * branch            master     -> FETCH_HEAD
    fatal: 拒绝合并无关的历史
    

    解决方法:
    在拉取时使用以下命令:

    git pull origin master --allow-unrelated-histories 
    

    对此,官方解释如下:

    By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently. As that is a very rare occasion, no configuration variable to enable this by default exists and will not be added.
    默认情况下,git合并命令拒绝合并没有共同祖先的历史。当两个项目的历史独立地开始时,这个选项可以被用来覆盖这个安全。由于这是一个非常少见的情况,因此没有默认存在的配置变量,也不会添加。(有道翻译)

    之后在执行:

    git push origin master
    

    相关文章

      网友评论

          本文标题:git pull 拉取更新失败

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