- On what does it depend whether you can use
git diff and
diff for the same file?
Simply if the file is in a git repo working tree, then you would be able to use
git diff to show changes for that file (against the same file as referenced by the git repo, like the index or blob objects).
This differs from '
diff', which compares files (meaning you need two files, not just one as in git diff when used in a git repo)
As hvd points out in the comments:
You can use
git diff outside any work tree and pass it two files.
So you can use
git diff in pretty much any situation you can use
The reverse is not true
git diff --color-words --no-index file1 file2
- And what are the differences between the formats?
git diff can emulate any diff format (unified, raw, ...).
It has git-specific format as well (
git diff will include a git header, with a "similarity index".
The hunks displays for each chunk of diffs are very similar to a diff -u.
- If you cannot exchange the commands (see 1.) how can you convert the files into the other format so that you can use them with the other command?
You can convert a
git diff in a raw format, or patch with raw:
The reverse is possible: you can apply a diff to a git repo.
- If you can exchange the commands (see 1.): Is it even recommend to do so?
It is if you don't have git installed (see the previous example)
- Are there any other notable differences in the files created by the two commands?
No: the result of applying a patch generated by a
diff or a
git diff should be the same.