8

I'd like to open a git diff output with VS Code. When I run git diff | code -, it opens in VS Code, but the file extension is set to .txt. I can manually "Change Language Mode" to Diff, but how can I do this automatically when viewing diffs in VS Code. I'd like to avoid always associating .txt with Diff if possible.

typeoneerror
  • 55,990
  • 32
  • 132
  • 223
  • Looking for the same, seem to work in vim: https://stackoverflow.com/questions/8359277/git-show-to-different-editor#comment30235163_8360614 – u123 May 10 '21 at 18:01

1 Answers1

0

If it's acceptable to use a different command, I would use the git difftool. As written in the documentation page

git difftool is a frontend to git diff and accepts the same options and arguments

I followed this article to configure VS Code as a difftool.

From a birds eye view:
Add VS Code to git config with these commands
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'

Then it is possible to call git difftool ReadMe.md. It brings up the VS Code with the diff window.

zerocukor287
  • 555
  • 2
  • 8
  • 23