15

What is the difference between git diff and git difftool?

I see that I can edit the configuration file for git to easily change the external tool used when I invoke git difftool and it seems that git diff outputs patches to the command line.

Why would I want to use git diff?

vmrob
  • 2,966
  • 29
  • 40

2 Answers2

12

As you and WKPlus said, git difftool will use an external tool, while git diff will show the diff directly in the terminal.

To answer your last question about when you would want to use git diff, you can think some of these ones :

  1. You do not have a GUI, so you can only use a terminal output
  2. You do not have an external tool
  3. You do not want to launch a "heavy" external tool and just want to quickly check the diff between two versions

Many other example can be imagined, and maybe you will find some of them yourself using git on daily basis.

mithrop
  • 3,283
  • 2
  • 21
  • 40
  • Ah, that simple. I think my problem was expecting something a little more complex. – vmrob Jan 06 '14 at 14:05
  • 2
    actually you can setup `git diff` to run a GUI or other tool... `git config --global diff.external ` as shown here https://stackoverflow.com/a/255212/253127 – nmz787 Jan 19 '19 at 01:03
  • Why you wouldn't want to do this, and instead set the external tool as the `difftool` rather than `diff` is because the command-line output will show ALL changes in the terminal at once, while the difftools usually only pop open a GUI one file at a time.. if you have a lot of changes to review quickly, the GUI popup is slower, likely requires you to scroll with the mouse, and switching back and forth from the keyboard slows things down even more. – nmz787 Jan 19 '19 at 01:03
1

git difftool will show you the diff in some tool (for example: vimdiff) and allow you to edit directly.

If you only want to check the changes you just did, I think git diff is more convenient.

It seems like since use vim can read a file and then why I want to use cat?

WKPlus
  • 6,955
  • 2
  • 35
  • 53