| 1 | git-diff(1) |
| 2 | =========== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
| 6 | git-diff - Show changes between commits, commit and working tree, etc |
| 7 | |
| 8 | |
| 9 | SYNOPSIS |
| 10 | -------- |
| 11 | [synopsis] |
| 12 | git diff [<options>] [<commit>] [--] [<path>...] |
| 13 | git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...] |
| 14 | git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...] |
| 15 | git diff [<options>] <commit>...<commit> [--] [<path>...] |
| 16 | git diff [<options>] <blob> <blob> |
| 17 | git diff [<options>] --no-index [--] <path> <path> [<pathspec>...] |
| 18 | |
| 19 | DESCRIPTION |
| 20 | ----------- |
| 21 | Show changes between the working tree and the index or a tree, changes |
| 22 | between the index and a tree, changes between two trees, changes resulting |
| 23 | from a merge, changes between two blob objects, or changes between two |
| 24 | files on disk. |
| 25 | |
| 26 | `git diff [<options>] [--] [<path>...]`:: |
| 27 | |
| 28 | This form is to view the changes you made relative to |
| 29 | the index (staging area for the next commit). In other |
| 30 | words, the differences are what you _could_ tell Git to |
| 31 | further add to the index but you still haven't. You can |
| 32 | stage these changes by using linkgit:git-add[1]. |
| 33 | |
| 34 | `git diff [<options>] --no-index [--] <path> <path> [<pathspec>...]`:: |
| 35 | |
| 36 | This form is to compare the given two paths on the |
| 37 | filesystem. You can omit the `--no-index` option when |
| 38 | running the command in a working tree controlled by Git and |
| 39 | at least one of the paths points outside the working tree, |
| 40 | or when running the command outside a working tree |
| 41 | controlled by Git. This form implies `--exit-code`. If both |
| 42 | paths point to directories, additional pathspecs may be |
| 43 | provided. These will limit the files included in the |
| 44 | difference. All such pathspecs must be relative as they |
| 45 | apply to both sides of the diff. |
| 46 | |
| 47 | `git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]`:: |
| 48 | |
| 49 | This form is to view the changes you staged for the next |
| 50 | commit relative to the named _<commit>_. Typically you |
| 51 | would want comparison with the latest commit, so if you |
| 52 | do not give _<commit>_, it defaults to `HEAD`. |
| 53 | If `HEAD` does not exist (e.g. unborn branches) and |
| 54 | _<commit>_ is not given, it shows all staged changes. |
| 55 | `--staged` is a synonym of `--cached`. |
| 56 | + |
| 57 | If `--merge-base` is given, instead of using _<commit>_, use the merge base |
| 58 | of _<commit>_ and `HEAD`. `git diff --cached --merge-base A` is equivalent to |
| 59 | `git diff --cached $(git merge-base A HEAD)`. |
| 60 | |
| 61 | `git diff [<options>] [--merge-base] <commit> [--] [<path>...]`:: |
| 62 | |
| 63 | This form is to view the changes you have in your |
| 64 | working tree relative to the named _<commit>_. You can |
| 65 | use `HEAD` to compare it with the latest commit, or a |
| 66 | branch name to compare with the tip of a different |
| 67 | branch. |
| 68 | + |
| 69 | If `--merge-base` is given, instead of using _<commit>_, use the merge base |
| 70 | of _<commit>_ and `HEAD`. `git diff --merge-base A` is equivalent to |
| 71 | `git diff $(git merge-base A HEAD)`. |
| 72 | |
| 73 | `git diff [<options>] [--merge-base] <commit> <commit> [--] [<path>...]`:: |
| 74 | |
| 75 | This is to view the changes between two arbitrary |
| 76 | _<commit>_. |
| 77 | + |
| 78 | If `--merge-base` is given, use the merge base of the two commits for the |
| 79 | "before" side. `git diff --merge-base A B` is equivalent to |
| 80 | `git diff $(git merge-base A B) B`. |
| 81 | |
| 82 | `git diff [<options>] <commit> <commit>...<commit> [--] [<path>...]`:: |
| 83 | |
| 84 | This form is to view the results of a merge commit. The first |
| 85 | listed _<commit>_ must be the merge itself; the remaining two or |
| 86 | more commits should be its parents. Convenient ways to produce |
| 87 | the desired set of revisions are to use the suffixes `@` and |
| 88 | `^!`. If `A` is a merge commit, then `git diff A A^@`, |
| 89 | `git diff A^!` and `git show A` all give the same combined diff. |
| 90 | |
| 91 | `git diff [<options>] <commit>..<commit> [--] [<path>...]`:: |
| 92 | |
| 93 | This is synonymous to the earlier form (without the `..`) for |
| 94 | viewing the changes between two arbitrary _<commit>_. If _<commit>_ on |
| 95 | one side is omitted, it will have the same effect as |
| 96 | using `HEAD` instead. |
| 97 | |
| 98 | `git diff [<options>] <commit>...<commit> [--] [<path>...]`:: |
| 99 | |
| 100 | This form is to view the changes on the branch containing |
| 101 | and up to the second _<commit>_, starting at a common ancestor |
| 102 | of both _<commit>_. `git diff A...B` is equivalent to |
| 103 | `git diff $(git merge-base A B) B`. You can omit any one |
| 104 | of _<commit>_, which has the same effect as using `HEAD` instead. |
| 105 | |
| 106 | Just in case you are doing something exotic, it should be |
| 107 | noted that all of the _<commit>_ in the above description, except |
| 108 | in the `--merge-base` case and in the last two forms that use `..` |
| 109 | notations, can be any _<tree>_. A tree of interest is the one pointed to |
| 110 | by the ref named `AUTO_MERGE`, which is written by the `ort` merge |
| 111 | strategy upon hitting merge conflicts (see linkgit:git-merge[1]). |
| 112 | Comparing the working tree with `AUTO_MERGE` shows changes you've made |
| 113 | so far to resolve textual conflicts (see the examples below). |
| 114 | |
| 115 | For a more complete list of ways to spell _<commit>_, see |
| 116 | "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7]. |
| 117 | However, `diff` is about comparing two _endpoints_, not ranges, |
| 118 | and the range notations (`<commit>..<commit>` and `<commit>...<commit>`) |
| 119 | do not mean a range as defined in the |
| 120 | "SPECIFYING RANGES" section in linkgit:gitrevisions[7]. |
| 121 | |
| 122 | `git diff [<options>] <blob> <blob>`:: |
| 123 | |
| 124 | This form is to view the differences between the raw |
| 125 | contents of two blob objects. |
| 126 | |
| 127 | OPTIONS |
| 128 | ------- |
| 129 | :git-diff: 1 |
| 130 | include::diff-options.adoc[] |
| 131 | |
| 132 | `-1`:: |
| 133 | `--base`:: |
| 134 | `-2`:: |
| 135 | `--ours`:: |
| 136 | `-3`:: |
| 137 | `--theirs`:: |
| 138 | Compare the working tree with |
| 139 | + |
| 140 | -- |
| 141 | * the "base" version (stage #1) when using `-1` or `--base`, |
| 142 | * "our branch" (stage #2) when using `-2` or `--ours`, or |
| 143 | * "their branch" (stage #3) when using `-3` or `--theirs`. |
| 144 | -- |
| 145 | + |
| 146 | The index contains these stages only for unmerged entries i.e. |
| 147 | while resolving conflicts. See linkgit:git-read-tree[1] |
| 148 | section "3-Way Merge" for detailed information. |
| 149 | |
| 150 | `-0`:: |
| 151 | Omit diff output for unmerged entries and just show |
| 152 | "Unmerged". Can be used only when comparing the working tree |
| 153 | with the index. |
| 154 | |
| 155 | `<path>...`:: |
| 156 | The _<path>_ parameters, when given, are used to limit |
| 157 | the diff to the named paths (you can give directory |
| 158 | names and get diff for all files under them). |
| 159 | |
| 160 | |
| 161 | include::diff-format.adoc[] |
| 162 | |
| 163 | EXAMPLES |
| 164 | -------- |
| 165 | |
| 166 | Various ways to check your working tree:: |
| 167 | + |
| 168 | ------------ |
| 169 | $ git diff <1> |
| 170 | $ git diff --cached <2> |
| 171 | $ git diff HEAD <3> |
| 172 | $ git diff AUTO_MERGE <4> |
| 173 | ------------ |
| 174 | + |
| 175 | <1> Changes in the working tree not yet staged for the next commit. |
| 176 | <2> Changes between the index and your last commit; what you |
| 177 | would be committing if you run `git commit` without `-a` option. |
| 178 | <3> Changes in the working tree since your last commit; what you |
| 179 | would be committing if you run `git commit -a` |
| 180 | <4> Changes in the working tree you've made to resolve textual |
| 181 | conflicts so far. |
| 182 | |
| 183 | Comparing with arbitrary commits:: |
| 184 | + |
| 185 | ------------ |
| 186 | $ git diff test <1> |
| 187 | $ git diff HEAD -- ./test <2> |
| 188 | $ git diff HEAD^ HEAD <3> |
| 189 | ------------ |
| 190 | + |
| 191 | <1> Instead of using the tip of the current branch, compare with the |
| 192 | tip of "test" branch. |
| 193 | <2> Instead of comparing with the tip of "test" branch, compare with |
| 194 | the tip of the current branch, but limit the comparison to the |
| 195 | file "test". |
| 196 | <3> Compare the version before the last commit and the last commit. |
| 197 | |
| 198 | Comparing branches:: |
| 199 | + |
| 200 | ------------ |
| 201 | $ git diff topic master <1> |
| 202 | $ git diff topic..master <2> |
| 203 | $ git diff topic...master <3> |
| 204 | ------------ |
| 205 | + |
| 206 | <1> Changes between the tips of the topic and the master branches. |
| 207 | <2> Same as above. |
| 208 | <3> Changes that occurred on the master branch since when the topic |
| 209 | branch was started off it. |
| 210 | |
| 211 | Limiting the diff output:: |
| 212 | + |
| 213 | ------------ |
| 214 | $ git diff --diff-filter=MRC <1> |
| 215 | $ git diff --name-status <2> |
| 216 | $ git diff arch/i386 include/asm-i386 <3> |
| 217 | ------------ |
| 218 | + |
| 219 | <1> Show only modification, rename, and copy, but not addition |
| 220 | or deletion. |
| 221 | <2> Show only names and the nature of change, but not actual |
| 222 | diff output. |
| 223 | <3> Limit diff output to named subtrees. |
| 224 | |
| 225 | Munging the diff output:: |
| 226 | + |
| 227 | ------------ |
| 228 | $ git diff --find-copies-harder -B -C <1> |
| 229 | $ git diff -R <2> |
| 230 | ------------ |
| 231 | + |
| 232 | <1> Spend extra cycles to find renames, copies and complete |
| 233 | rewrites (very expensive). |
| 234 | <2> Output diff in reverse. |
| 235 | |
| 236 | CONFIGURATION |
| 237 | ------------- |
| 238 | |
| 239 | include::includes/cmd-config-section-all.adoc[] |
| 240 | |
| 241 | :git-diff: 1 |
| 242 | include::config/diff.adoc[] |
| 243 | |
| 244 | SEE ALSO |
| 245 | -------- |
| 246 | `diff`(1), |
| 247 | linkgit:git-difftool[1], |
| 248 | linkgit:git-log[1], |
| 249 | linkgit:gitdiffcore[7], |
| 250 | linkgit:git-format-patch[1], |
| 251 | linkgit:git-apply[1], |
| 252 | linkgit:git-show[1] |
| 253 | |
| 254 | GIT |
| 255 | --- |
| 256 | Part of the linkgit:git[1] suite |