Using Git in Windows, msysgit is the first choice, but the shell of msysgit is not powerful, the size cannot be changed, and the font is ugly. Therefore, in Windows, using Git in Cygwin is a good choice.
Before submitting the code, or merging the code to view the code modification, we often need to diff to see what changes are there, and the diff output is obscure. When there are too many changes, like tianshu. After Git 1.7, you have a difftool command, which allows you to select a diff tool you like to view the differences between different commits. This tool can be a command line tool such as vimdiff or a GUI such as Winmerge.
There are many Diff tools in Windows, such as WinMerge (free of charge) and Araxis Merge (charged). If TortoiseSVN is installed, TortioseIDiff is also provided.
Here we recommend a SourceGear MergeDiff that supports Windows, Mac, and Linux, which is very useful.
1. Diff
First, create a script/usr/bin/mydiff. sh and use the following content:
#!/bin/sh"$(cygpath -u "C:\Program Files\SourceGear\Common\DiffMerge\sgdm")" \ -caption="DiffMerge For Git" -nosplash $(cygpath -w $1) $(cygpath -w $2)
Then use our tool in Git
# Set the execution permission
> Chmod a + x/usr/bin/mydiff. sh
# Add a diff tool> git config -- global diff. tool mydiff # configure mydiff command> git config -- global difftool. mydiff. cmd "mydiff. sh \ "\ $ LOCAL \" \ "\ $ REMOTE \" # view changes to the current directory> git difftool # Use-y, you don't have to ask each time> git difftool-y # view the differences between the two versions> git difftool HEAD ~ 2 HEAD
2. Merge
In the same way, we can also use a custom Merge tool.
First, create a script/usr/bin/mymerge. sh with the following content:
#!/bin/sh# path for DiffMergeDMPATH="C:\Program Files\SourceGear\Common\DiffMerge\sgdm"BASEPATH=$(cygpath -w -a "$1")LOCALPATH=$(cygpath -w -a "$2")REMOTEPATH=$(cygpath -w -a "$3")RESULTPATH=$(cygpath -w -a "$4")if [ ! -f $1 ]then echo "No Base, Use Empty" TMPBASE="/tmp/git-empty-base" touch $TMPBASE BASEPATH=$(cygpath -w -a "$TMPBASE")fi# echo "Base: ""$BASEPATH"# echo "Local: ""$LOCALPATH"# echo "Remote: ""$REMOTEPATH"# echo "Result: ""$RESULTPATH""$(cygpath -u "$DMPATH")" -caption="DiffMerge For Git" -nosplash \ -merge -result "$RESULTPATH" -t1=Mine -t2=Merged -t3=Theirs \ "$LOCALPATH" "$BASEPATH" "$REMOTEPATH"
Then set mymerge. sh
> Git config -- global merge. tool mymerge> git config -- global mergetool. mymerge. cmd "mymerge. sh \ "\ $ BASE \" \ "\ $ LOCAL \" \ "\ $ REMOTE \" \ "\ $ MERGED \" "> git config -- global mergetool. mymerge. trustExitCode false # When merge conflicts with rebase> git mergetool
3. Color
When using git status in msysgit, you will find that it has a color output, which looks intuitive. In fact, you can set it.
> git config --global color.diff auto> git config --global color.status auto> git config --global color.branch auto> git config --global color.interactive true
Or directly modify ~ /. Gitconfig
[diff] tool = mydiff[difftool "mydiff"] cmd = mydiff.sh \"$LOCAL\" \"$REMOTE\"[color] diff = auto status = auto branch = auto interactive = true[alias] st = status lg = log -p lol = log --graph --decorate --pretty=oneline --abbrev-commit lola = log --graph --decorate --pretty=oneline --abbrev-commit --all ls = ls-files[core] autocrlf = true[merge] tool = mymerge[mergetool "mymerge"] cmd = mymerge.sh \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\" trustExitCode = false
The log is more intuitive.