How to Configure diff and Merge Tool in Visual Studio Git Tools
If you are using Visual Studio plugin for Git, but you have also configured Git with MSys git, probably you could be surprised by some Visual Studio behavior.
Join the DZone community and get the full member experience.
Join For Freeif you are using visual studio plugin for git, but you have also configured git with msys git, probably you could be surprised by some visual studio behavior. the most obvious one is that commits are done using the wrong user.name and user.email configuration as i’ve described in visual studio tools for git, a primer, other one can be: tools used to do merge and diff during conflicts .
suppose you are working with visual studio , you issue a pull and find that there is some conflicts in repository.
figure 1: pull operation has a conflict
now you should resolve all conflicts before being able to continue work: you can click on file name that is conflicting and you are presented with a ui different from the one you are used with standard tfs source control.
figure 2: ui to manage conflicts when you are using git in visual studio
if you press “compare files” to visualize diff of files, it could happen that kdiff3 is opened to visualize the difference, instead of resolving directly inside visual studio .
figure 3: file compare is done with kdiff3 instead of visualizing them inside visual studio
this happens because visual studio git plugin uses standard git configuration, your local repository probably does not have any specific tools for diff and merge (unless you configured them), so global settings are honored. to verify actual settings you can open a git bash on the repository, issue a git config –list command and look at merge.tool and diff.tool settings
figure 4: actual configuration for merge and diff tools
since i’ve configured kdiff3 as standard conflict resolution tool after i installed msysgit, visual studio honors this settings and opens kdiff3 to do the diff, even if i’m inside the ide of vs. if you prefer using visual studio you should configure vs as diff and merge tools and you can choose to configure this at repository level or at global level . to change only a local repository, open .git folder and edit config file adding this piece of configuration.
1
tool = vsdiffmerge
[difftool]
prompt = true
[difftool "vsdiffmerge"]
cmd = "c:\program files (x86)\microsoft visual studio 11.0\common7\ide\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 11.0\common7\ide\vsdiffmerge.exe" "$remote" "$local" "$base" "$merged" //m
keepbackup = false
trustexistcode = true
if you want to change global configuration, you should edit a file named .gitconfig usually located inside your profile folder (c:usersyourname).
you can edit config file with a standard notepad or text editor, it is a simple text configuration file. once saved, return to visual studio and choose again to compare files, you should now being able to resolve conflicts directly from visual studio . if you like this option you can setup visual studio as diff and merge tool in global git configuration, so it will be available for every repository you are working with.
figure 5: once configured, visual studio is used as a diff tool for git repository
you can use visual studio not only for diff, but also for merge; press merge button and you will be prompted with a merge ui.
figure 6: merge tool of visual studio
once a file is merged, you can press the “accept merge” button in the top left area to resolve conflict and once all conflicts are resolved, you can go to commit pane and commit locally result of merge operations, and everything is done from inside visual studio.
Published at DZone with permission of Ricci Gian Maria, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments