1. 程式人生 > >git解決沖突方式

git解決沖突方式

發布 git pull false revert das pre xxxxxx code 安裝

Git解決沖突

  1. 安裝beyond compare 4

2.配置git對比工具

#difftool 配置

git config --global diff.tool bc4

git config --global difftool.bc4.cmd "\" C:/Program Files/Beyond Compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\""

git difftool HEAD // 比較當前修改情況

#mergeftool 配置

git config --global merge.tool bc4

git config --global mergetool.bc4.cmd"\" C:/Program Files/Beyond Compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\""

git config --global mergetool.bc4.trustExitCode true

#讓git mergetool不再生成備份文件(*.orig)

git config --global mergetool.keepBackup false

  1. 任務分支合並沖突解決

1.在目標分支上撤銷任務分支代碼

1)切換到目標分支

Git checkout G4

Git pull

2)檢查目標分支上是否有任務分支代碼合並過

Git log –oneline –grep=”E00P00-123”

3)若已合並過則撤銷任務代碼並提交

Git revert –no-commit $(git log –pretty=”%h” –grep=”E00P00-123”)

Git commit –m “xxx E00P00-123 XXXXXXXXX#任務代碼撤銷”

若未合並過或撤銷有沖突則跳過此步

2.將任務分支合並到目標分支

Git merge –squash origin/E00P00-123

3.若合並有沖突則解決沖突

1)查看沖突文件

Git status

2)打開合並工具

Git mergetool

3) 出現bc界面後解決沖突

4.沖突解決完畢後提交代碼

Git commit –m “xxx E00P00-123 XXXXX”

  1. 推送分支

Git push

  1. 集成分支、develop、master分支合並沖突解決(以集成分支G3合並到develop分支為例)

1.合並集成分支到develop

Git checkout develop

git pull

git merge –no-commit origin/G3

2.若有沖突則使用對比工具解決沖突(同合並任務分支解決方式一樣)

Git mergetool

3.沖突解決完畢後提交代碼

git commit –m “XXX E00P00-124 XXXXXX” (以發布任務標題作為提交日誌)

4.推送分支

Git push

git解決沖突方式