實例流程
多人協作基本
人員A push 更新至遠端庫時發生錯誤:
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/redquinoa/health-checks.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.
原因是另一個協作人員B 對同一個遠端分支 (branch)的同個檔案,有上傳 (push) 過其他較新的異動 (commit)。
人員A 處理流程如下:
- 更新遠端分支至本地,並且與本地分支做合併:
git pull
- 上述的自動合併,如果發生 Automatic merge failed,繼續下面步驟,手動排除衝突的內容。
- 檢視遠端分支最近做過哪些更動:
git log --graph --onleline --all
git log -p origin/master
- 手動修改衝突的檔案內容
- 檢視檔案包含 <<<< HEAD 與 >>>>>> something 標記的內容
- 完成後執行檢查與再上傳
git add
git status
git commit
git push
更新遠端分支
Remote branch: refactor
git checkout -b refactor
: 複製遠端分支至本地庫,並切換本地庫到這分支- 開始修改程式碼
git commit -a -m "Something"
: 步驟 2, 3 可執行多次git push -u origin refactor
: 更新遠端庫,第一次上傳至遠端 branch 需要加上參數-u origin refactor
之後再上傳可以忽略。
No Comments