DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Runtime FinOps: Making Cloud Cost Observable
  • Shrink a Bloated Git Repository and Optimize Pack Files
  • Open-Source GitOps at the Edge: Deploying to Thousands of Clusters With Rancher Fleet
  • From Command Lines to Intent Interfaces: Reframing Git Workflows Using Model Context Protocol

Trending

  • What Is Plagiarism? How to Avoid It and Cite Sources
  • Exactly-Once Processing: Myth vs Reality
  • How to Format Articles for DZone
  • Detecting Bugs and Vulnerabilities in Java With SonarQube
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. How to Configure diff and Merge Tool in Visual Studio Git Tools

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.

By 
Ricci Gian Maria user avatar
Ricci Gian Maria
·
Mar. 20, 13 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
75.5K Views

Join the DZone community and get the full member experience.

Join For Free

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. 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.

image

 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.

image

 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  .

image

 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 

image

 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.

image

 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.

image

 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.

Git Diff

Published at DZone with permission of Ricci Gian Maria. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Runtime FinOps: Making Cloud Cost Observable
  • Shrink a Bloated Git Repository and Optimize Pack Files
  • Open-Source GitOps at the Edge: Deploying to Thousands of Clusters With Rancher Fleet
  • From Command Lines to Intent Interfaces: Reframing Git Workflows Using Model Context Protocol

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook