Setup and Config
Getting and Creating Projects
Basic Snapshotting
Branching and Merging
Sharing and Updating Projects
Inspection and Comparison
Patching
Debugging
External Systems
Server Admin
Guides
- gitattributes
- Command-line interface conventions
- Everyday Git
- Frequently Asked Questions (FAQ)
- Glossary
- Hooks
- gitignore
- gitmodules
- Revisions
- Submodules
- Tutorial
- Workflows
- All guides...
Administration
Plumbing Commands
-
2.52.0
2025-11-17
- 2.51.1 → 2.51.2 no changes
-
2.51.0
2025-08-18
- 2.49.1 → 2.50.1 no changes
- 2.49.0 no changes
- 2.48.1 → 2.48.2 no changes
-
2.48.0
2025-01-10
- 2.47.1 → 2.47.3 no changes
-
2.47.0
2024-10-06
- 2.46.1 → 2.46.4 no changes
-
2.46.0
2024-07-29
- 2.45.4 no changes
-
2.45.3
2024-11-26
- 2.45.1 → 2.45.2 no changes
-
2.45.0
2024-04-29
- 2.44.1 → 2.44.4 no changes
-
2.44.0
2024-02-23
- 2.43.2 → 2.43.7 no changes
-
2.43.1
2024-02-09
-
2.43.0
2023-11-20
- 2.42.2 → 2.42.4 no changes
-
2.42.1
2023-11-02
-
2.42.0
2023-08-21
- 2.41.1 → 2.41.3 no changes
-
2.41.0
2023-06-01
- 2.40.1 → 2.40.4 no changes
-
2.40.0
2023-03-12
- 2.39.1 → 2.39.5 no changes
-
2.39.0
2022-12-12
- 2.38.1 → 2.38.5 no changes
-
2.38.0
2022-10-02
- 2.37.3 → 2.37.7 no changes
-
2.37.2
2022-08-11
- 2.36.1 → 2.37.1 no changes
-
2.36.0
2022-04-18
- 2.34.1 → 2.35.8 no changes
-
2.34.0
2021-11-15
- 2.33.1 → 2.33.8 no changes
-
2.33.0
2021-08-16
- 2.32.1 → 2.32.7 no changes
-
2.32.0
2021-06-06
- 2.31.1 → 2.31.8 no changes
-
2.31.0
2021-03-15
- 2.30.1 → 2.30.9 no changes
-
2.30.0
2020-12-27
- 2.29.1 → 2.29.3 no changes
-
2.29.0
2020-10-19
- 2.28.1 no changes
-
2.28.0
2020-07-27
- 2.25.2 → 2.27.1 no changes
-
2.25.1
2020-02-17
-
2.25.0
2020-01-13
- 2.24.1 → 2.24.4 no changes
-
2.24.0
2019-11-04
- 2.22.1 → 2.23.4 no changes
-
2.22.0
2019-06-07
- 2.21.1 → 2.21.4 no changes
-
2.21.0
2019-02-24
- 2.20.1 → 2.20.5 no changes
-
2.20.0
2018-12-09
- 2.19.3 → 2.19.6 no changes
-
2.19.2
2018-11-21
- 2.19.1 no changes
-
2.19.0
2018-09-10
- 2.18.1 → 2.18.5 no changes
-
2.18.0
2018-06-21
- 2.17.1 → 2.17.6 no changes
-
2.17.0
2018-04-02
-
2.16.6
2019-12-06
-
2.15.4
2019-12-06
-
2.14.6
2019-12-06
-
2.13.7
2018-05-22
-
2.12.5
2017-09-22
-
2.11.4
2017-09-22
- 2.10.5 no changes
-
2.9.5
2017-07-30
-
2.8.6
2017-07-30
- 2.7.6 no changes
-
2.6.7
2017-05-05
-
2.5.6
2017-05-05
-
2.4.12
2017-05-05
-
2.3.10
2015-09-28
- 2.1.4 → 2.2.3 no changes
-
2.0.5
2014-12-17
SYNOPSIS
git diff [options] [<commit>] [--] [<path>…] git diff [options] --cached [<commit>] [--] [<path>…] git diff [options] <commit> <commit> [--] [<path>…] git diff [options] <blob> <blob> git diff [options] [--no-index] [--] <path> <path>
DESCRIPTION
Show changes between the working tree and the index or a tree, changes between the index and a tree, changes between two trees, changes between two blob objects, or changes between two files on disk.
- git diff [--options] [--] [<path>…]
-
This form is to view the changes you made relative to the index (staging area for the next commit). In other words, the differences are what you could tell Git to further add to the index but you still haven’t. You can stage these changes by using git-add[1].
- git diff --no-index [--options] [--] [<path>…]
-
This form is to compare the given two paths on the filesystem. You can omit the
--no-indexoption when running the command in a working tree controlled by Git and at least one of the paths points outside the working tree, or when running the command outside a working tree controlled by Git. - git diff [--options] --cached [<commit>] [--] [<path>…]
-
This form is to view the changes you staged for the next commit relative to the named <commit>. Typically you would want comparison with the latest commit, so if you do not give <commit>, it defaults to HEAD. If HEAD does not exist (e.g. unborn branches) and <commit> is not given, it shows all staged changes. --staged is a synonym of --cached.
- git diff [--options] <commit> [--] [<path>…]
-
This form is to view the changes you have in your working tree relative to the named <commit>. You can use HEAD to compare it with the latest commit, or a branch name to compare with the tip of a different branch.
- git diff [--options] <commit> <commit> [--] [<path>…]
-
This is to view the changes between two arbitrary <commit>.
- git diff [--options] <commit>..<commit> [--] [<path>…]
-
This is synonymous to the previous form. If <commit> on one side is omitted, it will have the same effect as using HEAD instead.
- git diff [--options] <commit>...<commit> [--] [<path>…]
-
This form is to view the changes on the branch containing and up to the second <commit>, starting at a common ancestor of both <commit>. "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B". You can omit any one of <commit>, which has the same effect as using HEAD instead.
Just in case if you are doing something exotic, it should be noted that all of the <commit> in the above description, except in the last two forms that use ".." notations, can be any <tree>.
For a more complete list of ways to spell <commit>, see "SPECIFYING REVISIONS" section in gitrevisions[7]. However, "diff" is about comparing two endpoints, not ranges, and the range notations ("<commit>..<commit>" and "<commit>...<commit>") do not mean a range as defined in the "SPECIFYING RANGES" section in gitrevisions[7].
OPTIONS
- -p
- -u
- --patch
-
Generate patch (see section on generating patches). This is the default.
- -s
- --no-patch
-
Suppress diff output. Useful for commands like
gitshowthat show the patch by default, or to cancel the effect of--patch. - -U<n>
- --unified=<n>
-
Generate diffs with <n> lines of context instead of the usual three. Implies
-p. - --raw
-
Generate the diff in raw format.
- --patch-with-raw
-
Synonym for
-p--raw. - --indent-heuristic
- --no-indent-heuristic
-
These are to help debugging and tuning experimental heuristics (which are off by default) that shift diff hunk boundaries to make patches easier to read.
- --minimal
-
Spend extra time to make sure the smallest possible diff is produced.
- --patience
-
Generate a diff using the "patience diff" algorithm.
- --histogram
-
Generate a diff using the "histogram diff" algorithm.
- --diff-algorithm={patience|minimal|histogram|myers}
-
Choose a diff algorithm. The variants are as follows:
default,myers-
The basic greedy diff algorithm. Currently, this is the default.
minimal-
Spend extra time to make sure the smallest possible diff is produced.
patience-
Use "patience diff" algorithm when generating patches.
histogram-
This algorithm extends the patience algorithm to "support low-occurrence common elements".
For instance, if you configured diff.algorithm variable to a non-default value and want to use the default one, then you have to use
--diff-algorithm=defaultoption. - --stat[=<width>[,<name-width>[,<count>]]]
-
Generate a diffstat. By default, as much space as necessary will be used for the filename part, and the rest for the graph part. Maximum width defaults to terminal width, or 80 columns if not connected to a terminal, and can be overridden by <width>. The width of the filename part can be limited by giving another width <name-width> after a comma. The width of the graph part can be limited by using
--stat-graph-width=<width> (affects all commands generating a stat graph) or by settingdiff.statGraphWidth=<width> (does not affectgitformat-patch). By giving a third parameter <count>, you can limit the output to the first <count> lines, followed by ... if there are more.These parameters can also be set individually with
--stat-width=<width>,--stat-name-width=<name-width> and--stat-count=<count>. - --numstat
-
Similar to
--stat, but shows number of added and deleted lines in decimal notation and pathname without abbreviation, to make it more machine friendly. For binary files, outputs two-instead of saying00. - --shortstat
-
Output only the last line of the
--statformat containing total number of modified files, as well as number of added and deleted lines. - --dirstat[=<param1,param2,…>]
-
Output the distribution of relative amount of changes for each sub-directory. The behavior of
--dirstatcan be customized by passing it a comma separated list of parameters. The defaults are controlled by thediff.dirstatconfiguration variable (see git-config[1]). The following parameters are available:changes-
Compute the dirstat numbers by counting the lines that have been removed from the source, or added to the destination. This ignores the amount of pure code movements within a file. In other words, rearranging lines in a file is not counted as much as other changes. This is the default behavior when no parameter is given.
lines-
Compute the dirstat numbers by doing the regular line-based diff analysis, and summing the removed/added line counts. (For binary files, count 64-byte chunks instead, since binary files have no natural concept of lines). This is a more expensive
--dirstatbehavior than thechangesbehavior, but it does count rearranged lines within a file as much as other changes. The resulting output is consistent with what you get from the other--*statoptions. files-
Compute the dirstat numbers by counting the number of files changed. Each changed file counts equally in the dirstat analysis. This is the computationally cheapest
--dirstatbehavior, since it does not have to look at the file contents at all. cumulative-
Count changes in a child directory for the parent directory as well. Note that when using
cumulative, the sum of the percentages reported may exceed 100%. The default (non-cumulative) behavior can be specified with thenoncumulativeparameter. - <limit>
-
An integer parameter specifies a cut-off percent (3% by default). Directories contributing less than this percentage of the changes are not shown in the output.
Example: The following will count changed files, while ignoring directories with less than 10% of the total amount of changed files, and accumulating child directory counts in the parent directories:
--dirstat=files,10,cumulative. - --summary
-
Output a condensed summary of extended header information such as creations, renames and mode changes.
- --patch-with-stat
-
Synonym for
-p--stat. - -z
-
When
--raw,--numstat,--name-onlyor--name-statushas been given, do not munge pathnames and use NULs as output field terminators.Without this option, pathnames with "unusual" characters are quoted as explained for the configuration variable
core.quotePath(see git-config[1]). - --name-only
-
Show only names of changed files.
- --name-status
-
Show only names and status of changed files. See the description of the
--diff-filteroption on what the status letters mean. - --submodule[=<format>]
-
Specify how differences in submodules are shown. When specifying
--submodule=shortthe short format is used. This format just shows the names of the commits at the beginning and end of the range. When--submoduleor--submodule=logis specified, the log format is used. This format lists the commits in the range like git-submodule[1]summarydoes. When--submodule=diffis specified, the diff format is used. This format shows an inline diff of the changes in the submodule contents between the commit range. Defaults todiff.submoduleor the short format if the config option is unset. - --color[=<when>]
-
Show colored diff.
--color(i.e. without =<when>) is the same as--color=always. <when> can be one ofalways,never, orauto. It can be changed by thecolor.uiandcolor.diffconfiguration settings. - --no-color
-
Turn off colored diff. This can be used to override configuration settings. It is the same as
--color=never. - --word-diff[=<mode>]
-
Show a word diff, using the <mode> to delimit changed words. By default, words are delimited by whitespace; see
--word-diff-regexbelow. The <mode> defaults to plain, and must be one of:- color
-
Highlight changed words using only colors. Implies
--color. - plain
-
Show words as [
-removed-] and{+added+}. Makes no attempts to escape the delimiters if they appear in the input, so the output may be ambiguous. - porcelain
-
Use a special line-based format intended for script consumption. Added/removed/unchanged runs are printed in the usual unified diff format, starting with a
+/-/` ` character at the beginning of the line and extending to the end of the line. Newlines in the input are represented by a tilde~on a line of its own. - none
-
Disable word diff again.
Note that despite the name of the first mode, color is used to highlight the changed parts in all modes if enabled.
- --word-diff-regex=<regex>
-
Use <regex> to decide what a word is, instead of considering runs of non-whitespace to be a word. Also implies
--word-diffunless it was already enabled.Every non-overlapping match of the <regex> is considered a word. Anything between these matches is considered whitespace and ignored(!) for the purposes of finding differences. You may want to append |[
^[:space:]] to your regular expression to make sure that it matches all non-whitespace characters. A match that contains a newline is silently truncated(!) at the newline.For example,
--word-diff-regex=.will treat each character as a word and, correspondingly, show differences character by character.The regex can also be set via a diff driver or configuration option, see gitattributes[5] or git-config[1]. Giving it explicitly overrides any diff driver or configuration setting. Diff drivers override configuration settings.
- --color-words[=<regex>]
-
Equivalent to
--word-diff=colorplus (if a regex was specified)--word-diff-regex=<regex>. - --no-renames
-
Turn off rename detection, even when the configuration file gives the default to do so.
- --check
-
Warn if changes introduce conflict markers or whitespace errors. What are considered whitespace errors is controlled by
core.whitespaceconfiguration. By default, trailing whitespaces (including lines that solely consist of whitespaces) and a space character that is immediately followed by a tab character inside the initial indent of the line are considered whitespace errors. Exits with non-zero status if problems are found. Not compatible with --exit-code. - --ws-error-highlight=<kind>
-
Highlight whitespace errors on lines specified by <kind> in the color specified by
color.diff.whitespace. <kind> is a comma separated list ofold,new,context. When this option is not given, only whitespace errors innewlines are highlighted. E.g.--ws-error-highlight=new,oldhighlights whitespace errors on both deleted and added lines.allcan be used as a short-hand forold,new,context. Thediff.wsErrorHighlightconfiguration variable can be used to specify the default behaviour. - --full-index
-
Instead of the first handful of characters, show the full pre- and post-image blob object names on the "index" line when generating patch format output.
- --binary
-
In addition to
--full-index, output a binary diff that can be applied withgit-apply.