diff-format.txt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. Raw output format
  2. -----------------
  3. The raw output format from "git-diff-index", "git-diff-tree",
  4. "git-diff-files" and "git diff --raw" are very similar.
  5. These commands all compare two sets of things; what is
  6. compared differs:
  7. git-diff-index <tree-ish>::
  8. compares the <tree-ish> and the files on the filesystem.
  9. git-diff-index --cached <tree-ish>::
  10. compares the <tree-ish> and the index.
  11. git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]::
  12. compares the trees named by the two arguments.
  13. git-diff-files [<pattern>...]::
  14. compares the index and the files on the filesystem.
  15. The "git-diff-tree" command begins its output by printing the hash of
  16. what is being compared. After that, all the commands print one output
  17. line per changed file.
  18. An output line is formatted this way:
  19. ------------------------------------------------
  20. in-place edit :100644 100644 bcd1234 0123456 M file0
  21. copy-edit :100644 100644 abcd123 1234567 C68 file1 file2
  22. rename-edit :100644 100644 abcd123 1234567 R86 file1 file3
  23. create :000000 100644 0000000 1234567 A file4
  24. delete :100644 000000 1234567 0000000 D file5
  25. unmerged :000000 000000 0000000 0000000 U file6
  26. ------------------------------------------------
  27. That is, from the left to the right:
  28. . a colon.
  29. . mode for "src"; 000000 if creation or unmerged.
  30. . a space.
  31. . mode for "dst"; 000000 if deletion or unmerged.
  32. . a space.
  33. . sha1 for "src"; 0\{40\} if creation or unmerged.
  34. . a space.
  35. . sha1 for "dst"; 0\{40\} if creation, unmerged or "look at work tree".
  36. . a space.
  37. . status, followed by optional "score" number.
  38. . a tab or a NUL when `-z` option is used.
  39. . path for "src"
  40. . a tab or a NUL when `-z` option is used; only exists for C or R.
  41. . path for "dst"; only exists for C or R.
  42. . an LF or a NUL when `-z` option is used, to terminate the record.
  43. Possible status letters are:
  44. - A: addition of a file
  45. - C: copy of a file into a new one
  46. - D: deletion of a file
  47. - M: modification of the contents or mode of a file
  48. - R: renaming of a file
  49. - T: change in the type of the file
  50. - U: file is unmerged (you must complete the merge before it can
  51. be committed)
  52. - X: "unknown" change type (most probably a bug, please report it)
  53. Status letters C and R are always followed by a score (denoting the
  54. percentage of similarity between the source and target of the move or
  55. copy). Status letter M may be followed by a score (denoting the
  56. percentage of dissimilarity) for file rewrites.
  57. <sha1> is shown as all 0's if a file is new on the filesystem
  58. and it is out of sync with the index.
  59. Example:
  60. ------------------------------------------------
  61. :100644 100644 5be4a4a 0000000 M file.c
  62. ------------------------------------------------
  63. Without the `-z` option, pathnames with "unusual" characters are
  64. quoted as explained for the configuration variable `core.quotePath`
  65. (see linkgit:git-config[1]). Using `-z` the filename is output
  66. verbatim and the line is terminated by a NUL byte.
  67. diff format for merges
  68. ----------------------
  69. "git-diff-tree", "git-diff-files" and "git-diff --raw"
  70. can take `-c` or `--cc` option
  71. to generate diff output also for merge commits. The output differs
  72. from the format described above in the following way:
  73. . there is a colon for each parent
  74. . there are more "src" modes and "src" sha1
  75. . status is concatenated status characters for each parent
  76. . no optional "score" number
  77. . tab-separated pathname(s) of the file
  78. For `-c` and `--cc`, only the destination or final path is shown even
  79. if the file was renamed on any side of history. With
  80. `--combined-all-paths`, the name of the path in each parent is shown
  81. followed by the name of the path in the merge commit.
  82. Examples for `-c` and `--cc` without `--combined-all-paths`:
  83. ------------------------------------------------
  84. ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM desc.c
  85. ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM bar.sh
  86. ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR phooey.c
  87. ------------------------------------------------
  88. Examples when `--combined-all-paths` added to either `-c` or `--cc`:
  89. ------------------------------------------------
  90. ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM desc.c desc.c desc.c
  91. ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM foo.sh bar.sh bar.sh
  92. ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR fooey.c fuey.c phooey.c
  93. ------------------------------------------------
  94. Note that 'combined diff' lists only files which were modified from
  95. all parents.
  96. include::diff-generate-patch.txt[]
  97. other diff formats
  98. ------------------
  99. The `--summary` option describes newly added, deleted, renamed and
  100. copied files. The `--stat` option adds diffstat(1) graph to the
  101. output. These options can be combined with other options, such as
  102. `-p`, and are meant for human consumption.
  103. When showing a change that involves a rename or a copy, `--stat` output
  104. formats the pathnames compactly by combining common prefix and suffix of
  105. the pathnames. For example, a change that moves `arch/i386/Makefile` to
  106. `arch/x86/Makefile` while modifying 4 lines will be shown like this:
  107. ------------------------------------
  108. arch/{i386 => x86}/Makefile | 4 +--
  109. ------------------------------------
  110. The `--numstat` option gives the diffstat(1) information but is designed
  111. for easier machine consumption. An entry in `--numstat` output looks
  112. like this:
  113. ----------------------------------------
  114. 1 2 README
  115. 3 1 arch/{i386 => x86}/Makefile
  116. ----------------------------------------
  117. That is, from left to right:
  118. . the number of added lines;
  119. . a tab;
  120. . the number of deleted lines;
  121. . a tab;
  122. . pathname (possibly with rename/copy information);
  123. . a newline.
  124. When `-z` output option is in effect, the output is formatted this way:
  125. ----------------------------------------
  126. 1 2 README NUL
  127. 3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
  128. ----------------------------------------
  129. That is:
  130. . the number of added lines;
  131. . a tab;
  132. . the number of deleted lines;
  133. . a tab;
  134. . a NUL (only exists if renamed/copied);
  135. . pathname in preimage;
  136. . a NUL (only exists if renamed/copied);
  137. . pathname in postimage (only exists if renamed/copied);
  138. . a NUL.
  139. The extra `NUL` before the preimage path in renamed case is to allow
  140. scripts that read the output to tell if the current record being read is
  141. a single-path record or a rename/copy record without reading ahead.
  142. After reading added and deleted lines, reading up to `NUL` would yield
  143. the pathname, but if that is `NUL`, the record will show two paths.