Git多個遠程倉庫不一樣步時的補救辦法

遠程倉庫間出現差別

git本地倉庫是能夠與多個遠程倉庫關聯的,若是想知道怎麼配置,請參考Git如何使用多個託管平臺管理代碼html

git remote關聯了多個遠程倉庫時,總會遇到一些問題。今天就遇到了兩個遠程倉庫不一樣步致使沒法push的狀況。git

大概狀況是這樣的,我是一個本地倉庫關聯了githubgitee兩個遠程倉庫。github

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文件,致使兩個遠程倉庫出現了差別。因此當我在本地完成了一部分功能,準備提交到遠程倉庫時,出現了報錯。shell

$ 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的代碼拉到本地masterbash

$ 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推送到遠程allhexo

$ 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
複製代碼

問題得以解決!fetch


掃一掃下方小程序碼或搜索Tusi博客,即刻閱讀最新文章!ui

Tusi博客
相關文章
相關標籤/搜索