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.55.0
2026-06-29
-
2.54.0
2026-04-20
-
2.53.0
2026-02-02
-
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
gitdiff[<options>] [<commit>] [--] [<path>…]gitdiff[<options>]--cached[--merge-base] [<commit>] [--] [<path>…]gitdiff[<options>] [--merge-base] <commit> [<commit>…] <commit> [--] [<path>…]gitdiff[<options>] <commit>...<commit> [--] [<path>…]gitdiff[<options>] <blob> <blob>gitdiff[<options>]--no-index[--] <path> <path> [<pathspec>…]
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.
gitdiff[<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].
gitdiff[<options>]--no-index[--] <path> <path> [<pathspec>...]-
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. If both paths point to directories, additional pathspecs may be provided. These will limit the files included in the difference. All such pathspecs must be relative as they apply to both sides of the diff. gitdiff[<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. IfHEADdoes not exist (e.g. unborn branches) and <commit> is not given, it shows all staged changes.--stagedis a synonym of--cached.If
--merge-baseis given, instead of using <commit>, use the merge base of <commit> andHEAD.gitdiff--cached--merge-baseAis equivalent togitdiff--cached$(gitmerge-baseAHEAD). gitdiff[<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
HEADto compare it with the latest commit, or a branch name to compare with the tip of a different branch.If
--merge-baseis given, instead of using <commit>, use the merge base of <commit> andHEAD.gitdiff--merge-baseAis equivalent togitdiff$(gitmerge-baseAHEAD). gitdiff[<options>] [--merge-base] <commit> <commit> [--] [<path>...]-
This is to view the changes between two arbitrary <commit>.
If
--merge-baseis given, use the merge base of the two commits for the "before" side.gitdiff--merge-baseABis equivalent togitdiff$(gitmerge-baseAB)B. gitdiff[<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. Convenient ways to produce the desired set of revisions are to use the suffixes
@and^!. IfAis a merge commit, thengitdiffAA^@,gitdiffA^!andgitshowAall give the same combined diff. gitdiff[<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 usingHEADinstead. gitdiff[<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 usingHEADinstead.
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>. A tree of interest is the one pointed to
by the ref named AUTO_MERGE, which is written by the ort merge
strategy upon hitting merge conflicts (see git-merge[1]).
Comparing the working tree with AUTO_MERGE shows changes you’ve made
so far to resolve textual conflicts (see the examples below).
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 Generating patch text with -p). This is the default.
-s--no-patch-
Suppress all output from the diff machinery. Useful for commands like
gitshowthat show the patch by default to squelch their output, or to cancel the effect of options like--patch,--statearlier on the command line in an alias. -U<n>--unified=<n>-
Generate diffs with <n> lines of context. The number of context lines defaults to
diff.contextor 3 if the configuration variable is unset. (-Uwithout <n> is silently accepted as a synonym for-pdue to a historical accident). 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 <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:
defaultmyers-
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 or by setting
diff.statNameWidth=<name-width>. The width of the graph part can be limited by using--stat-graph-width=<graph-width> or by settingdiff.statGraphWidth=<graph-width>. Using--stator--stat-graph-widthaffects all commands generating a stat graph, while settingdiff.statNameWidthordiff.statGraphWidthdoes 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
+lif it’s a symlink) and mode changes (+xor-xfor 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[<param>,...]--dirstat[=<param>,...]-
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[=<param>,...]-
Synonym for
--dirstat=files,<param>,.... --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 the name of each changed file in the post-image tree. 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 the name(s) and status of each changed file. 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=shorttheshortformat is used. This format just shows the names of the commits at the beginning and end of the range. When--submoduleor--submodule=logis specified, thelogformat is used. This format lists the commits in the range like git-submodule[1]summarydoes. When--submodule=diffis specified, thediffformat is used. This format shows an inline diff of the changes in the submodule contents between the commit range. Defaults todiff.submoduleor theshortformat 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 tonoif the option is not given and tozebraif 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. Similarlycolor.diff.oldMovedwill 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)Movedcolor. Adjacent blocks cannot be told apart. zebra-
Blocks of moved text are detected as in