当前位置:   article > 正文

Git多个远程仓库不同步时的补救办法_git push之后远端没有同步合入

git push之后远端没有同步合入

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
  • 1
  • 2

由于不小心在远程仓库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.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

解决方案

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

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

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.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

再将本地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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

问题得以解决!


首发连接


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

Tusi博客

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/452756
推荐阅读
相关标签
  

闽ICP备14008679号