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 [--merge-base] [<commit>] [--] [<path>…] git diff [<options>] [--merge-base] <commit> [<commit>…] <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 resulting from a merge, 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 [<options>] --no-index [--] <path> <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. This form implies--exit-code. - git diff [<options>] --cached [--merge-base] [<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.
If --merge-base is given, instead of using <commit>, use the merge base of <commit> and HEAD.
gitdiff--cached--merge-baseAis equivalent togitdiff--cached$(gitmerge-baseAHEAD). - git diff [<options>] [--merge-base] <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.
If --merge-base is given, instead of using <commit>, use the merge base of <commit> and HEAD.
gitdiff--merge-baseAis equivalent togitdiff$(gitmerge-baseAHEAD). - git diff [<options>] [--merge-base] <commit> <commit> [--] [<path>…]
-
This is to view the changes between two arbitrary <commit>.
If --merge-base is given, use the merge base of the two commits for the "before" side.
gitdiff--merge-baseABis equivalent togitdiff$(gitmerge-baseAB)B. - git diff [<options>] <commit> <commit>… <commit> [--] [<path>…]
-
This form is to view the results of a merge commit. The first listed <commit> must be the merge itself; the remaining two or more commits should be its parents. A convenient way to produce the desired set of revisions is to use the
^@suffix. For instance, ifmasternames a merge commit,gitdiffmastermaster^@gives the same combined diff asgitshowmaster. - git diff [<options>] <commit>..<commit> [--] [<path>…]
-
This is synonymous to the earlier form (without the
..) for viewing the changes between two arbitrary <commit>. 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>.
gitdiffA...Bis equivalent togitdiff$(gitmerge-baseAB)B. You can omit any one of <commit>, which has the same effect as using HEAD instead.
Just in case you are doing something exotic, it should be
noted that all of the <commit> in the above description, except
in the --merge-base case and 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
--patch. - --output=<file>
-
Output to a specific file instead of stdout.
- --output-indicator-new=<char>
- --output-indicator-old=<char>
- --output-indicator-context=<char>
-
Specify the character used to indicate new, old or context lines in the generated patch. Normally they are +, - and ' ' respectively.
- --raw
-
Generate the diff in raw format.
- --patch-with-raw
-
Synonym for
-p--raw. - --indent-heuristic
-
Enable the heuristic that shifts diff hunk boundaries to make patches easier to read. This is the default.
- --no-indent-heuristic
-
Disable the indent heuristic.
- --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.
- --anchored=<text>
-
Generate a diff using the "anchored diff" algorithm.
This option may be specified more than once.
If a line exists in both the source and destination, exists only once, and starts with this text, this algorithm attempts to prevent it from appearing as a deletion or addition in the output. It uses the "patience diff" algorithm internally.
- --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 the
diff.algorithmvariable 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>. - --compact-summary
-
Output a condensed summary of extended header information such as file creations or deletions ("new" or "gone", optionally "+l" if it’s a symlink) and mode changes ("+x" or "-x" for adding or removing executable bit respectively) in diffstat. The information is put between the filename part and the graph part. Implies
--stat. - --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. - -X[<param1,param2,…>]
- --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. - --cumulative
-
Synonym for --dirstat=cumulative
- --dirstat-by-file[=<param1,param2>…]
-
Synonym for --dirstat=files,param1,param2…
- --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. The file names are often encoded in UTF-8. For more information see the discussion about encoding in the git-log[1] manual page.
- --name-status
-
Show only names and status of changed files. See the description of the
--diff-filteroption on what the status letters mean. Just like--name-onlythe file names are often encoded in UTF-8. - --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. - --color-moved[=<mode>]
-
Moved lines of code are colored differently. It can be changed by the
diff.colorMovedconfiguration setting. The <mode> defaults to no if the option is not given and to zebra if the option with no mode is given. The mode must be one of:- no
-
Moved lines are not highlighted.
- default
-
Is a synonym for
zebra. This may change to a more sensible mode in the future. - plain
-
Any line that is added in one location and was removed in another location will be colored with color.diff.newMoved. Similarly color.diff.oldMoved will be used for removed lines that are added somewhere else in the diff. This mode picks up any moved line, but it is not very useful in a review to determine if a block of code was moved without permutation.
- blocks
-
Blocks of moved text of at least 20 alphanumeric characters are detected greedily. The detected blocks are painted using either the color.diff.{old,new}Moved color. Adjacent blocks cannot be told apart.
- zebra
-
Blocks of moved text are detected as in blocks mode. The blocks are painted using either the color.diff.{old,new}Moved color or color.diff.{old,new}MovedAlternative. The change between the two colors indicates that a new block was detected.
- dimmed-zebra
-
Similar to zebra, but additional dimming of uninteresting parts of moved code is performed. The bordering lines of two adjacent blocks are considered interesting, the rest is uninteresting.
dimmed_zebrais a deprecated synonym.
- --no-color-moved
-
Turn off move detection. This can be used to override configuration settings. It is the same as
--color-moved=no. - --color-moved-ws=<modes>
-
This configures how whitespace is ignored when performing the move detection for
--color-moved. It can be set by thediff.colorMovedWSconfiguration setting. These modes can be given as a comma separated list:- no
-
Do not ignore whitespace when performing move detection.
- ignore-space-at-eol
-
Ignore changes in whitespace at EOL.
- ignore-space-change
-
Ignore changes in amount of whitespace. This ignores whitespace at line end, and considers all other sequences of one or more whitespace characters to be equivalent.
- ignore-all-space
-
Ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none.
- allow-indentation-change
-
Initially ignore any whitespace in the move detection, then group the moved code blocks only into a block if the change in whitespace is the same per line. This is incompatible with the other modes.
- --no-color-moved-ws
-
Do not ignore whitespace when performing move detection. This can be used to override configuration settings. It is the same as
--color-moved-ws=no. - --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: