# Git 之疑難雜症 - 遠端與本地衝突/分支的合併 ###### tags: `Git` ## Current Change v.s. Incoming Change - 遇到遠端與本地衝突怎辦 (in VScode) #### 當 Merge 後修改到相同程式碼位置時,發生衝突 (這裡的 Change 都是指相較於上一個在本地 commit 的版本) - `Current Change` 代表自己本地的改變 (自己寫的 / 本地) - `Incoming Change` 代表合併進來的改變 (別人寫的 / 遠端) #### 可以點擊以下四種操作或是加上手動修正,來處理衝突 - Accept Current Change 將會直接使用"自己本地的改變" would **ignore completely what you merge**, and keep what you had. - Accept Incoming Change 將會直接使用"合併進來的改變" would **ignore completely what you had**, and keep what you merge. - Accept Both Changes 兩者都保留 - Compare Changes 可以用於進階比較每行差異(較少使用) ## rebase 或 merge - 分支的合併 情境:  已有分支 bugfix 與主幹 master,想將現行 bugfix 合併到 master,有以下兩種方式 **rebase** 或 **merge**,==差別在於留下的歷史資料不同==。 ### merge 最後結果(留下的紀錄):  :::success pros: - 會將 history 保存, 任何看到 GIT history 的人都可以看到你 merge 的操作 ::: :::danger cons: - 合併後的 history 會變得更複雜 ::: ### rebase 最後結果(留下的紀錄):  :::success pros: - 不會在合併時產生多餘的 commit,乾淨! - Rebase 不會將 history 保存, 任何看到 GIT history 的人永遠不知道你做了這次 rebase ::: :::danger cons: - 會比使用 merge 更容易發生衝突 - 破壞性操作, 搬家之後把原本的地方夷平(沒有人知道你來過,也回不去) ::: ## 參考資料 - [git 解衝突步驟](https://cmmobile.gitbook.io/cmiosbook/ji-ben-gong-ju/git-pian) - 分支的合併 與圖片來源:[Merging vs. Rebasing -atlassian](https://www.atlassian.com/git/tutorials/merging-vs-rebasing) - [合併分支【分支】 | 連猴子都能懂的Git入門指南](https://backlog.com/git-tutorial/tw/stepup/stepup1_4.html) - [git merge 與 rebase 之間的差異?](https://ithelp.ithome.com.tw/questions/10209820)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up