git-diff.txt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. git-diff(1)
  2. ===========
  3. NAME
  4. ----
  5. git-diff - Show changes between commits, commit and working tree, etc
  6. SYNOPSIS
  7. --------
  8. [verse]
  9. 'git diff' [<options>] [<commit>] [--] [<path>...]
  10. 'git diff' [<options>] --cached [<commit>] [--] [<path>...]
  11. 'git diff' [<options>] <commit> [<commit>...] <commit> [--] [<path>...]
  12. 'git diff' [<options>] <commit>...<commit> [--] [<path>...]
  13. 'git diff' [<options>] <blob> <blob>
  14. 'git diff' [<options>] --no-index [--] <path> <path>
  15. DESCRIPTION
  16. -----------
  17. Show changes between the working tree and the index or a tree, changes
  18. between the index and a tree, changes between two trees, changes resulting
  19. from a merge, changes between two blob objects, or changes between two
  20. files on disk.
  21. 'git diff' [<options>] [--] [<path>...]::
  22. This form is to view the changes you made relative to
  23. the index (staging area for the next commit). In other
  24. words, the differences are what you _could_ tell Git to
  25. further add to the index but you still haven't. You can
  26. stage these changes by using linkgit:git-add[1].
  27. 'git diff' [<options>] --no-index [--] <path> <path>::
  28. This form is to compare the given two paths on the
  29. filesystem. You can omit the `--no-index` option when
  30. running the command in a working tree controlled by Git and
  31. at least one of the paths points outside the working tree,
  32. or when running the command outside a working tree
  33. controlled by Git. This form implies `--exit-code`.
  34. 'git diff' [<options>] --cached [<commit>] [--] [<path>...]::
  35. This form is to view the changes you staged for the next
  36. commit relative to the named <commit>. Typically you
  37. would want comparison with the latest commit, so if you
  38. do not give <commit>, it defaults to HEAD.
  39. If HEAD does not exist (e.g. unborn branches) and
  40. <commit> is not given, it shows all staged changes.
  41. --staged is a synonym of --cached.
  42. 'git diff' [<options>] <commit> [--] [<path>...]::
  43. This form is to view the changes you have in your
  44. working tree relative to the named <commit>. You can
  45. use HEAD to compare it with the latest commit, or a
  46. branch name to compare with the tip of a different
  47. branch.
  48. 'git diff' [<options>] <commit> <commit> [--] [<path>...]::
  49. This is to view the changes between two arbitrary
  50. <commit>.
  51. 'git diff' [<options>] <commit> <commit>... <commit> [--] [<path>...]::
  52. This form is to view the results of a merge commit. The first
  53. listed <commit> must be the merge itself; the remaining two or
  54. more commits should be its parents. A convenient way to produce
  55. the desired set of revisions is to use the {caret}@ suffix.
  56. For instance, if `master` names a merge commit, `git diff master
  57. master^@` gives the same combined diff as `git show master`.
  58. 'git diff' [<options>] <commit>..<commit> [--] [<path>...]::
  59. This is synonymous to the earlier form (without the "..") for
  60. viewing the changes between two arbitrary <commit>. If <commit> on
  61. one side is omitted, it will have the same effect as
  62. using HEAD instead.
  63. 'git diff' [<options>] <commit>\...<commit> [--] [<path>...]::
  64. This form is to view the changes on the branch containing
  65. and up to the second <commit>, starting at a common ancestor
  66. of both <commit>. "git diff A\...B" is equivalent to
  67. "git diff $(git merge-base A B) B". You can omit any one
  68. of <commit>, which has the same effect as using HEAD instead.
  69. Just in case you are doing something exotic, it should be
  70. noted that all of the <commit> in the above description, except
  71. in the last two forms that use ".." notations, can be any
  72. <tree>.
  73. For a more complete list of ways to spell <commit>, see
  74. "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7].
  75. However, "diff" is about comparing two _endpoints_, not ranges,
  76. and the range notations ("<commit>..<commit>" and
  77. "<commit>\...<commit>") do not mean a range as defined in the
  78. "SPECIFYING RANGES" section in linkgit:gitrevisions[7].
  79. 'git diff' [<options>] <blob> <blob>::
  80. This form is to view the differences between the raw
  81. contents of two blob objects.
  82. OPTIONS
  83. -------
  84. :git-diff: 1
  85. include::diff-options.txt[]
  86. -1 --base::
  87. -2 --ours::
  88. -3 --theirs::
  89. Compare the working tree with the "base" version (stage #1),
  90. "our branch" (stage #2) or "their branch" (stage #3). The
  91. index contains these stages only for unmerged entries i.e.
  92. while resolving conflicts. See linkgit:git-read-tree[1]
  93. section "3-Way Merge" for detailed information.
  94. -0::
  95. Omit diff output for unmerged entries and just show
  96. "Unmerged". Can be used only when comparing the working tree
  97. with the index.
  98. <path>...::
  99. The <paths> parameters, when given, are used to limit
  100. the diff to the named paths (you can give directory
  101. names and get diff for all files under them).
  102. include::diff-format.txt[]
  103. EXAMPLES
  104. --------
  105. Various ways to check your working tree::
  106. +
  107. ------------
  108. $ git diff <1>
  109. $ git diff --cached <2>
  110. $ git diff HEAD <3>
  111. ------------
  112. +
  113. <1> Changes in the working tree not yet staged for the next commit.
  114. <2> Changes between the index and your last commit; what you
  115. would be committing if you run "git commit" without "-a" option.
  116. <3> Changes in the working tree since your last commit; what you
  117. would be committing if you run "git commit -a"
  118. Comparing with arbitrary commits::
  119. +
  120. ------------
  121. $ git diff test <1>
  122. $ git diff HEAD -- ./test <2>
  123. $ git diff HEAD^ HEAD <3>
  124. ------------
  125. +
  126. <1> Instead of using the tip of the current branch, compare with the
  127. tip of "test" branch.
  128. <2> Instead of comparing with the tip of "test" branch, compare with
  129. the tip of the current branch, but limit the comparison to the
  130. file "test".
  131. <3> Compare the version before the last commit and the last commit.
  132. Comparing branches::
  133. +
  134. ------------
  135. $ git diff topic master <1>
  136. $ git diff topic..master <2>
  137. $ git diff topic...master <3>
  138. ------------
  139. +
  140. <1> Changes between the tips of the topic and the master branches.
  141. <2> Same as above.
  142. <3> Changes that occurred on the master branch since when the topic
  143. branch was started off it.
  144. Limiting the diff output::
  145. +
  146. ------------
  147. $ git diff --diff-filter=MRC <1>
  148. $ git diff --name-status <2>
  149. $ git diff arch/i386 include/asm-i386 <3>
  150. ------------
  151. +
  152. <1> Show only modification, rename, and copy, but not addition
  153. or deletion.
  154. <2> Show only names and the nature of change, but not actual
  155. diff output.
  156. <3> Limit diff output to named subtrees.
  157. Munging the diff output::
  158. +
  159. ------------
  160. $ git diff --find-copies-harder -B -C <1>
  161. $ git diff -R <2>
  162. ------------
  163. +
  164. <1> Spend extra cycles to find renames, copies and complete
  165. rewrites (very expensive).
  166. <2> Output diff in reverse.
  167. SEE ALSO
  168. --------
  169. diff(1),
  170. linkgit:git-difftool[1],
  171. linkgit:git-log[1],
  172. linkgit:gitdiffcore[7],
  173. linkgit:git-format-patch[1],
  174. linkgit:git-apply[1],
  175. linkgit:git-show[1]
  176. GIT
  177. ---
  178. Part of the linkgit:git[1] suite