How to diff a file between two branches using VS as your difftool – 107

Suppose you want to diff a specific file between two branches. The best* git command I’ve found is in this SO answer (only because I’ve found a couple of other sites reference it)

$ git diff branch-name path/to/file

The SO answer says to use `..` in front of branch-name, but I’ve found it works without it. There are WAY too many variants of these commands to keep track of.

I’d love to figure out where this command option is in the official docs but it is pretty overwhelming list.

In a previous tip, you saw how to use VS as your external diff tool. As the blog post title describes, here’s how to do it

$ git difftool branch-name path/to/file

for example, the name of my branch in the image below is `readme` and my filename is `readme.txt`.

I don’t have to provide a path to the readme file since it is at the same location as my current directory.

image

and volia Visual Studio appears**

diff of two different pearl jam song lyrics across branches

* I have no idea if this is the best answer. I’ve read that there’s old syntax and new syntax. I’d love to hear people’s suggestions in the comments!

**I’ve noticed in VS 2017 that VS must be running. Otherwise, the IDE is launched, but the tool doesn’t appear. If you re-run the command via command line, the dif will appear. YMMV

And yeah, I wonder what genre of music I listen to when I write 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s