說明 fetch、fast-forward 與 merge 的差異,補上衝突處理及中止方式。
適用:Git 2.x,repository 有 origin/master 和自己的工作分支。若主分支為 main,按實際名稱替換。
操作前
用 git status 確認未完成修改已提交或 stash,git branch --show-current 核對目前分支,git remote -v 確認來源。以下 feature-note 代表已存在的工作分支,不要套用到別人的分支。
git fetch origin
git switch master
git pull --ff-only origin master
git switch feature-note
git merge masterpull –ff-only 在本機與遠端已分岔時拒絕前進,讓你先判斷本機提交用途。只要取得最新主分支不一定要切換,可從工作分支直接 git merge origin/master,fetch 仍須先做。
衝突處理
merge 衝突時 status 列出檔案。檢查衝突區段兩側的意圖,修改成最終內容,移除標記,執行相關測試,再 git add 具體檔案、git commit 完成 merge。若需回到操作前,使用 git merge --abort,不是 reset –hard。
確認 git log --oneline --graph --decorate -10,看主分支提交是否已在工作分支歷史,並檢查實際功能。git rebase origin/master 是重排自己的提交而非建立 merge commit;已共享的歷史需團隊協調,不能把兩者當無差異替換。這個同步流程沒有替你推送分支。
冒險者留言
comments powered by Disqus