• Git多个远程仓库不同步时的补救办法


    git本地仓库是可以与多个远程仓库关联的,如果想知道怎么配置,请参考Git如何使用多个托管平台管理代码

    git remote关联了多个远程仓库时,总会遇到一些问题。今天就遇到了两个远程仓库不一致导致无法push的情况。

    远程仓库间出现差异

    大概情况是这样的,我是一个本地仓库关联了githubgitee两个远程仓库。

    git remote add all git@github.com:cumt-robin/BlogFrontEnd.git
    git remote set-url --add all git@gitee.com:tusi/BlogFrontEnd.git
    

    由于不小心在远程仓库gitee上手动修改了README.md文件,导致两个远程仓库出现了差异。所以当我在本地完成了一部分功能,准备提交到远程仓库时,出现了报错。

    $ git push all --all
    Everything up-to-date
    To gitee.com:tusi/BlogFrontEnd.git
     ! [rejected]        master -> master (fetch first)
    error: failed to push some refs to 'git@gitee.com:tusi/BlogFrontEnd.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.
    

    解决方案

    由于是gitee的仓库多修改了一点东西,因此在本地再加一个remote,单独关联gitee

    $ git remote add gitee git@gitee.com:tusi/BlogFrontEnd.git
    

    gitee的代码拉到本地master

    $ git pull gitee master
    remote: Enumerating objects: 1, done.
    remote: Counting objects: 100% (1/1), done.
    remote: Total 1 (delta 0), reused 0 (delta 0)
    Unpacking objects: 100% (1/1), done.
    From gitee.com:tusi/BlogFrontEnd
     * branch            master     -> FETCH_HEAD
     * [new branch]      master     -> gitee/master
    Already up to date!
    Merge made by the 'recursive' strategy.
    

    再将本地master推送到远程all

    $ git push all --all
    Enumerating objects: 2, done.
    Counting objects: 100% (2/2), done.
    Delta compression using up to 6 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (2/2), 499 bytes | 499.00 KiB/s, done.
    Total 2 (delta 0), reused 0 (delta 0)
    To github.com:cumt-robin/BlogFrontEnd.git
       1557ece..8391333  master -> master
    Enumerating objects: 2, done.
    Counting objects: 100% (2/2), done.
    Delta compression using up to 6 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (2/2), 917 bytes | 917.00 KiB/s, done.
    Total 2 (delta 0), reused 0 (delta 0)
    remote: Powered By Gitee.com
    To gitee.com:tusi/BlogFrontEnd.git
       8912ff5..8391333  master -> master
    

    问题得以解决!


    首发连接


    扫一扫下方小程序码或搜索Tusi博客,即刻阅读最新文章!

    Tusi博客

  • 相关阅读:
    Hibernate---对象的三种状态
    grunt+bower依赖管理
    grunt 的安装和简单使用
    sqlserver dmv 动态管理视图
    ado.net 数据库连接池
    桥接模式
    .net MVP
    主定理(分治算法)
    图中环的判断
    选举协议paxos 协议 理解
  • 原文地址:https://www.cnblogs.com/wenbinjiang/p/11891516.html
Copyright © 2020-2023  润新知