git的命令行貌似沒有特別好用的UI工具,不管是Android Studio自帶的還是其他的,完全代替命令行好像做不到。再加上對git來說沒什么比diff和merge更正常不過的事情了。那就配置命令行吧。
“Git鼓勵在工作流程中頻繁使用分支與合並,哪怕一天之內進行許多次都沒有關系。理解分支的概念並熟練運用后,你才會意識到為什么Git是一個如此強大而獨特的工具,並從此真正改變你的開發方式。” 不是我說的,但是很貼切。
我用的工具是 DiffMerge,比較輕,官網是:http://www.sourcegear.com/diffmerge/
安裝在 c 盤之后,需要在git里面配置下,DiffMerge_4.2.0.697.stable_x64 .msi,其中exe為C:\Program Files\SourceGear\Common\DiffMerge\sgdm.exe。
具體流程
1.安裝DiffMerge
2.配置sgdm.exe路徑C:\Program Files\SourceGear\Common\DiffMerge到windows環境變量的path下
3.配置git
git config --global diff.tool sgdm git config --global difftool.diffmerge.cmd 'sgdm "$LOCAL" "$REMOTE"' git config --global merge.tool sgdm git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"' git config --global mergetool.diffmerge.trustExitCode true
4.用DiffMerge
在代碼處理MERGING狀態時,可以用命令 git mergetool 啟動工具
補:
問題1:
工具會生成.orig文件,可以設置下,讓git不再生成:
git config --global mergetool.keepBackup false
問題2:
$ git mergetool git config option merge.tool set to unknown tool: sgdm Resetting to default... This message is displayed because 'merge.tool' is not configured. See 'git mergetool --tool-help' or 'git help config' for more details. 'git mergetool' will now attempt to use one of the following tools: tortoisemerge emerge vimdiff No files need merging
按照提示,說明git有對merge工具做校驗
13051041@CNHQ-13051041N MINGW64 /d/gittest/Test (temp|MERGING) $ git mergetool --tool-help 'git mergetool --tool=<tool>' may be set to one of the following: tortoisemerge vimdiff vimdiff2 vimdiff3 user-defined: diffmerge.cmd diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE" The following tools are valid, but not currently available: araxis bc bc3 codecompare deltawalker diffmerge diffuse ecmerge emerge gvimdiff gvimdiff2 gvimdiff3 kdiff3 meld opendiff p4merge tkdiff winmerge xxdiff Some of the tools listed above only work in a windowed environment. If run in a terminal-only session, they will fail.
我的解決方案是吧sgdm.exe文件復制一份,名字改成diffmerge.exe。還是放在他原來的文件夾下。
修改后,設置腳本所下所示:
git config --global diff.tool diffmerge git config --global difftool.diffmerge.cmd 'sgdm "$LOCAL" "$REMOTE"' git config --global merge.tool diffmerge git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"' git config --global mergetool.diffmerge.trustExitCode true git config --global mergetool.keepBackup false