Is git diff related to diff?

  1. Is git diff implemented based on diff?

  2. Is the command line syntax of git diff similar to that of diff? Does learning one help using the other much?

  3. are their output files following the same format? Can they be both used by git patch and patch? (Is there git patch? How is it related to patch?)



2 Answers 2


The file format is interoperable. Git uses the best format, diff -u. It also extends it to represent additional types of changes.

The equivalent to patch is git apply. It stages the changes in the index as well as applying them to the working tree.

I remember git apply being stricter than patch, although the reference documentation doesn't seem to make an explicit comparison. It does mention several tests / errors which can be enabled or disabled.

The reference documentation also suggests that it could be used as "a replacement for GNU patch" - even outside of a git repository, if you use a certain option.

  • One interesting question from the OP remains unanswered: "Is git diff implemented based on diff". Do you know about this @sourcejedi?
    – clapas
    Commented May 28, 2020 at 8:33
  • @clapas I don't know.
    – sourcejedi
    Commented May 28, 2020 at 9:04
  • I really don't think the patches are interoperable. git will prefix the source and dest files with a and b. Also git can make binary patches which diff doesn't understand.
    – qwr
    Commented Jul 12, 2020 at 3:08

git-diff offers more features than diff and I don't think the output patches are interoperable (without some additional options), since diff will produce lines like

diff -ruNa dir1/file1.txt dir2/file1.txt

while git-diff produces lines like

diff --git a/dir1/file1.txt b/dir2/file1.txt

(notice the source and dest prefix, toggleable with --no-prefix, and different options)

Here are some additional features of git-diff:

  • Can record moved/renamed files, while diff can't

  • Uses recursive mode, unified diffs, and handles new/deleted files by default (diff -ruN)

  • Supports different algorithms for finding differences

  • Supports git binary patches which encodes binary data as ASCII

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .