# 文件比较 diff

# 查看两个版本之间的文件变动

git diff 608e120 4abe32e --name-only

# 查看某个文件两个版本之间的变化

git diff commit_id1 commit_id2 -- index.html
git diff ffd98b:filename b8e7b0:filename

# 将 vscode 配置成为 difftool

# 先把 vscode 作为 git 默认编辑器

git config --global core.editor "code --wait"

# 用 vscode 打开 .gitconfig 文件

git config --global -e

# 配置文件

[core]
	editor = code --wait
[diff]
	tool = default-difftool
[mergetool]
    prompt = true
    keepBackup = false
[mergetool "code"]
    cmd = code --wait $MERGED
[difftool "default-difftool"]
	cmd = code --wait --diff $LOCAL $REMOTE

core.editor 是刚才已经配置好的,无须理会。

# 将 vs 配置成为 difftool

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\vsDiffMerge.exe

[diff]
    tool = vsdiffmerge
[difftool]
      prompt = true
[difftool "vsdiffmerge"]
      cmd = \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\vsDiffMerge.exe\" \"$LOCAL\" \"$REMOTE\" //t
      keepbackup = false
      trustexistcode = true
[merge]
      tool = vsdiffmerge
[mergetool]
      prompt = true
[mergetool "vsdiffmerge"]
      cmd = \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\vsDiffMerge.exe\" \"$LOCAL\" \"$REMOTE\" //t //m
      keepbackup = false
      trustexistcode = true
git config --global difftool.visualstudio.cmd "'C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer/vsdiffmerge.exe' \$LOCAL \$REMOTE Source Target //ignorespace //t"

git config --global mergetool.visualstudio.cmd "'C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer/vsdiffmerge.exe' \$LOCAL \$REMOTE \$BASE \$MERGED //ignorespace //m"
git config --global mergetool.visualstudio.trustExitCode true

git config --global diff.tool visualstudio
git config --global merge.tool visualstudio

验证可以,如果只安装了一个 vs 版本的话,可以把地址配置成环境变量里的 PATH ;另外 git difftool 1f3b21 HEAD -t vscode 的形式选择工具