git中配置Beyond Compare作為mergetool
One of the first real points of frustration a developer encounters with Git is the initial unresolved merge conflict. Beyond Compare is an excellent
file comparison utility and can be configured with Git as a merge and diff tool.
To setup diff on Linux, create a short wrapper script to pass the parameters in the correct order:
vi ~/git-diff-wrapper
1
2
3
4
|
#!/bin/sh # diff is called by git with 7 parameters: # path old-file old-hex old-mode new-file new-hex new-mode "/usr/bin/bcompare" "$2" "$5" | cat |
Windows users can configure this by entering the commands:
git config --global diff.tool bc3 git config --global difftool.bc3.path "C:\Program Files (x86)\Beyond Compare 3\BComp.exe"
Now edit your git config using the sample below to configure merging and use of the script above:
Linux
vi ~/.gitconfig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[user] name = First Last email = <a href="mailto:email@address.com">email@address.com</a> [color] ui = true [core] editor = nano [diff] external = ~/git-diff-wrapper [merge] tool = bc3 [mergetool "bc3"] cmd = bcompare \ "$PWD/$LOCAL" \ "$PWD/$REMOTE" \ "$PWD/$BASE" \ "$PWD/$MERGED" keepBackup = false trustExitCode = false |
This can be configured on a Windows machine similarly:
Windows
notepad C:\Program Files\git\etc\config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
[user] name = First Last email = <a href="mailto:email@address.com">email@address.com</a> [color] ui = true [core] editor = nano [merge] tool = bc3 [mergetool "bc3"] cmd = 'C:\Program Files (x86)\Beyond Compare 3\BComp.exe' \ "$PWD/$LOCAL" \ "$PWD/$REMOTE" \ "$PWD/$BASE" \ "$PWD/$MERGED" keepBackup = false trustExitCode = false |
Beyond Compare is not available for Mac OS X, checkout diffmerge for a similar solution. Here's a sample configuration:
OSX w/ diffmerge
vi ~/.gitconfig
1
2
3
4
5
6
7
8
9
10
11
12
|
[user] name = First Last email = <a href="mailto:email@address.com">email@address.com</a> [color] ui = true [core] editor = vi [merge] tool = diffmerge [mergetool "diffmerge"] cmd = diffmerge --merge --result=$MERGED $LOCAL $BASE $REMOTE trustExitCode = false |
Note the command line accepts 4 parameters:
- LOCAL – Current branch version
- REMOTE – Version to be merged
- BASE – Common ancestor
- MERGED – File where results will be written
Now you can use Beyond Compare for diff (git diff) and to handle conflicts.
The sequence of commands for a merge using mergetool would be:
- git merge
- git mergetool -t [tool]
- git add .
- git commit
For example:
Pull changes on a file that has been modified by another user:
git fetch origin git pull origin master From github.com:domain/project * branch master -> FETCH_HEAD Updating c44e43e..b3813c5 error: Entry 'filename.php' not uptodate. Cannot merge.
Attempt to update your changes with automatic merging:
git add filename.php git commit -m "made x changes" From github.com:domain/project * branch master -> FETCH_HEAD Auto-merging filename.php CONFLICT (content): Merge conflict in filename.php Automatic merge failed; fix conflicts and then commit the result.
Now merge using Beyond Compare:
git mergetool
If you complete the merge and save it, mergetool will accept the result. If not, you can accept changes, or use another version wholesale:
git checkout --ours filename.php git checkout --theirs filename.php
Commit the changes:
git add filename.php git commit -m "made x changes"
Verify:
git pull origin master From github.com:domain/project * branch master -> FETCH_HEAD Already up-to-date.
git mergetool also includes preconfigured support for a number of open source merge tools: kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff. These can be used with the -t flag:
git mergetool -t kdiff3
相關文章
- 中文Beyond Compare 4啟用安裝包+Beyond Compare 4金鑰
- Beyond Compare 5 記錄
- ubuntu 命令安裝 beyond compareUbuntu
- 中文Beyond Compare 4安裝包+Beyond Compare 4序號產生器金鑰
- Beyond Compare 4過期怎麼辦?Beyond Compare 4 Mac永 久金鑰分享Mac
- centos 使用 beyond compare 對比工具CentOS
- centos下如何使用 beyond compare 對比工具CentOS
- Beyond Compare 4 for Mac中文版下載Mac
- Beyond Compare v5.0.0.29773 破解版
- Beyond Compare 4 for Mac,檔案對比同步工具Mac
- Beyond Compare for Mac(檔案比較對比工具)Mac
- 檔案同步對比軟體:Beyond Compare 4 for MacMac
- Beyond Compare 4 for Mac:你的檔案比較神器Mac
- 超好用的檔案對比工具:Beyond Compare 4中文啟用
- Beyond Compare 4 for Mac(檔案同步對比工具)4.4.7中文版Mac
- 強大的檔案對比工具Beyond Compare 4 for MacMac
- beyond Compare4不需要補丁的破解方法
- Macos強大的檔案對比同步工具:Beyond Compare 4中文版Mac
- Beyond Compare 4 中文版 「Macos檔案同步對比工具」Mac
- Mac端強大好用的檔案對比工具:Beyond Compare 4中文版Mac
- Macos檔案同步對比工具:Beyond Compare 4 for Mac中文版Mac
- Beyond Compare 4金鑰啟用Mac版最新4.4.7「相容macos14」Mac
- mac檔案對比工具 Beyond Compare 4 4.4.7(28397)中文啟用版Mac
- Beyond Compare 4 for Mac 直觀高效的檔案同步對比合並工具Mac
- Centos中的git配置CentOSGit
- Mac 上超好用的程式碼對比工具 beyond compare,對比json差異MacJSON
- Beyond Compare 4 Mac金鑰啟用 附 完整安裝教程 支援M1Mac
- mac電腦檔案對比工具Beyond Compare 4 for Mac中文版下載Mac
- 檔案同步對比工具:Beyond Compare 4 for Mac v4.4.7(28397)中文版Mac
- 使用映象配置為 Git Clone 加速Git
- Beyond Compare 1.9f註冊演算法&序號產生器 (8千字)演算法
- Git 中 SSH Key 生成和配置Git
- 使用memorycache作為session共享配置Session
- 用 Git 作為聊天應用的後端Git後端
- 蘋果Mac電腦好用的檔案對比同步工具:Beyond Compare 4 中文版 最新啟用蘋果Mac
- git 配置Git
- C++中compare函式的使用C++函式
- git倉庫配置git sshGit