Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git学习笔记摘要4——比较合并工具设置 #157

Open
soapgu opened this issue Jul 29, 2022 · 0 comments
Open

Git学习笔记摘要4——比较合并工具设置 #157

soapgu opened this issue Jul 29, 2022 · 0 comments
Labels
Git IDE Good for newcomers

Comments

@soapgu
Copy link
Owner

soapgu commented Jul 29, 2022

  • 小问题

  1. 比较文件问题

git 的diff命令可以显示相关文件的差异
图片
虽然可以把所有差异全显示出来,但是不是“全地图视野”总觉得差了那么一点意思

  1. 合并文件问题
    至于合并冲突就更加过分了,把远端和本地的差异全部丢到文本里,都要自己手工处理。更加原始了。

当时在学习的时候,就产生过这样的疑问。无意中看到git 有 mergetool和difftool

  • mergetool和difftool的默认配置

默认配置启动difftool是使用vimdiff的

git difftool

This message is displayed because 'diff.tool' is not configured.
See 'git difftool --tool-help' or 'git help config' for more details.
'git difftool' will now attempt to use one of the following tools:
kompare emerge vimdiff nvimdiff

Viewing (1/2): 'roomboard_standard/roomboard/app/build.gradle'
Launch 'vimdiff' [Y/n]?

图片
嗯,已经比git diff的显示进步太多了。

但是如果说我还想要更加直接好用一点的工具那?
tool都可以自定义的。总有一款适合你

git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'

4条命令就搞定了,简单粗暴!
实验下效果

PS D:\s365-roomboard> git difftool --cached

Viewing (1/1): 'roomboard_standard/roomboard/app/src/main/res/drawable-v24/citybg.png'
Launch 'vscode' [Y/n]? y

图片
图片这种二进制也能比较了,很好

  • 再实验下mergetool
    PS D:\Github\GitLearn> git mergetool .\App.xaml.cs
    Merging:
    App.xaml.cs

Normal merge conflict for 'App.xaml.cs':
{local}: modified file
{remote}: modified file

图片
merge体验好多了!

  • 其他工具选择

当然如果对C# IDE工具有情怀的可以设置,这里不做详细介绍了

[diff]
	tool = vsdiffmerge
[difftool]
	prompt = true
[difftool "vsdiffmerge"]
	cmd = \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\vsdiffmerge.exe\" \"$LOCAL\" \"$REMOTE\" //t
	keepBackup = false
[merge]
	tool = vsdiffmerge
[mergetool]
	prompt = true
[mergetool "vsdiffmerge"]
	cmd = \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\vsdiffmerge.exe\" \"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" //m
	keepBackup = false
	trustExitCode = true
  • 最后一点点收尾

  1. 工具自由
    我们的 git mergetool/difftool 命令后面-t可以指定工具名
    这个我们可以多个工具,随自己喜欢了,当然默认工具还是可以用的,比如我还是喜欢vimdiff
PS D:\Github\GitLearn> git difftool -t vimdiff

Viewing (1/1): 'App.xaml.cs'
Launch 'vimdiff' [Y/n]?
  1. merge的备份文件
PS D:\Github\GitLearn> git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        App.xaml.cs.orig

nothing added to commit but untracked files present (use "git add" to track)

我们在用完mergetool以后会自动留下.orig备份文件。这是git“好心”万一你合并错了还有退路
当然你说你是高水,退路是不要考虑的,也是可以的
git config --global mergetool.keepBackup false
声明:个人喜好,风险自负

@soapgu soapgu added IDE Good for newcomers Git labels Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Git IDE Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant