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