(window.webpackJsonp=window.webpackJsonp||[]).push([[1123],{1531:function(e,t,a){"use strict";a.r(t);var s=a(31),i=Object(s.a)({},(function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[a("h1",{attrs:{id:"git-diff"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-diff"}},[e._v("#")]),e._v(" Git Diff")]),e._v(" "),a("h2",{attrs:{id:"show-differences-in-working-branch"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#show-differences-in-working-branch"}},[e._v("#")]),e._v(" Show differences in working branch")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff\n\n")])])]),a("p",[e._v("This will show the "),a("a",{attrs:{href:"http://stackoverflow.com/documentation/git/244/staging",target:"_blank",rel:"noopener noreferrer"}},[a("strong",[e._v("unstaged")]),a("OutboundLink")],1),e._v(" changes on the current branch from the commit before it. It will only show changes relative to the index, meaning it shows what you "),a("strong",[e._v("could")]),e._v(" add to the next commit, but haven't. To add (stage) these changes, you can use "),a("code",[e._v("git add")]),e._v(".")]),e._v(" "),a("p",[e._v("If a file is staged, but was modified after it was staged, "),a("code",[e._v("git diff")]),e._v(" will show the differences between the current file and the staged version.")]),e._v(" "),a("h2",{attrs:{id:"show-changes-between-two-commits"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#show-changes-between-two-commits"}},[e._v("#")]),e._v(" Show changes between two commits")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff 1234abc..6789def # old new\n\n")])])]),a("p",[e._v("E.g.: Show the changes made in the last 3 commits:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff @~3..@ # HEAD -3 HEAD\n\n")])])]),a("p",[e._v("Note: the two dots (..) is optional, but adds clarity.")]),e._v(" "),a("p",[e._v("This will show the textual difference between the commits, regardless of where they are in the tree.")]),e._v(" "),a("h2",{attrs:{id:"show-differences-for-staged-files"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#show-differences-for-staged-files"}},[e._v("#")]),e._v(" Show differences for staged files")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff --staged\n\n")])])]),a("p",[e._v("This will show the changes between the previous commit and the currently staged files.")]),e._v(" "),a("p",[a("strong",[e._v("NOTE:")]),e._v(" You can also use the following commands to accomplish the same thing:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff --cached\n\n")])])]),a("p",[e._v("Which is just a synonym for "),a("code",[e._v("--staged")]),e._v(" or")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git status -v\n\n")])])]),a("p",[e._v("Which will trigger the verbose settings of the "),a("code",[e._v("status")]),e._v(" command.")]),e._v(" "),a("h2",{attrs:{id:"comparing-branches"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#comparing-branches"}},[e._v("#")]),e._v(" Comparing branches")]),e._v(" "),a("p",[e._v("Show the changes between the tip of "),a("strong",[a("code",[e._v("new")])]),e._v(" and the tip of "),a("strong",[a("code",[e._v("original")])]),e._v(":")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff original new # equivalent to original..new\n\n")])])]),a("p",[e._v("Show all changes on "),a("strong",[a("code",[e._v("new")])]),e._v(" since it branched from "),a("strong",[a("code",[e._v("original")])]),e._v(":")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff original...new # equivalent to $(git merge-base original new)..new\n\n")])])]),a("p",[e._v("Using only one parameter such as")]),e._v(" "),a("p",[e._v("git diff original")]),e._v(" "),a("p",[e._v("is equivalent to")]),e._v(" "),a("p",[e._v("git diff original..HEAD")]),e._v(" "),a("h2",{attrs:{id:"show-both-staged-and-unstaged-changes"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#show-both-staged-and-unstaged-changes"}},[e._v("#")]),e._v(" Show both staged and unstaged changes")]),e._v(" "),a("p",[e._v("To show all staged "),a("strong",[e._v("and")]),e._v(" unstaged changes, use:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff HEAD\n\n")])])]),a("p",[a("strong",[e._v("NOTE:")]),e._v(" You can also use the following command:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git status -vv\n\n")])])]),a("p",[e._v("The difference being that the output of the latter will actually tell you which changes are staged for commit and which are not.")]),e._v(" "),a("h2",{attrs:{id:"show-differences-for-a-specific-file-or-directory"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#show-differences-for-a-specific-file-or-directory"}},[e._v("#")]),e._v(" Show differences for a specific file or directory")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff myfile.txt\n\n")])])]),a("p",[e._v("Shows the changes between the previous commit of the specified file ("),a("code",[e._v("myfile.txt")]),e._v(") and the locally-modified version that has not yet been staged.")]),e._v(" "),a("p",[e._v("This also works for directories:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff documentation\n\n")])])]),a("p",[e._v("The above shows the changes between the previous commit of all files in the specified directory ("),a("code",[e._v("documentation/")]),e._v(") and the locally-modified versions of these files, that have not yet been staged.")]),e._v(" "),a("p",[e._v("To show the difference between some version of a file in a given commit and the local "),a("code",[e._v("HEAD")]),e._v(" version you can specify the commit you want to compare against:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff 27fa75e myfile.txt\n\n")])])]),a("p",[e._v("Or if you want to see the version between two separate commits:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff 27fa75e ada9b57 myfile.txt\n\n")])])]),a("p",[e._v("To show the difference between the version specified by the hash "),a("code",[e._v("ada9b57")]),e._v(" and the latest commit on the branch "),a("code",[e._v("my_branchname")]),e._v(" for only the relative directory called "),a("code",[e._v("my_changed_directory/")]),e._v(" you can do this:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff ada9b57 my_branchname my_changed_directory/\n\n")])])]),a("h2",{attrs:{id:"viewing-a-word-diff-for-long-lines"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#viewing-a-word-diff-for-long-lines"}},[e._v("#")]),e._v(" Viewing a word-diff for long lines")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff [HEAD|--staged...] --word-diff\n\n")])])]),a("p",[e._v("Rather than displaying lines changed, this will display differences within lines. For example, rather than:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[a("span",{pre:!0,attrs:{class:"token deleted"}},[e._v("-Hello world")]),e._v("\n"),a("span",{pre:!0,attrs:{class:"token inserted"}},[e._v("+Hello world!")]),e._v("\n\n")])])]),a("p",[e._v("Where the whole line is marked as changed, "),a("code",[e._v("word-diff")]),e._v(" alters the output to:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("Hello [-world-]{+world!+}\n\n")])])]),a("p",[e._v("You can omit the markers "),a("code",[e._v("[-")]),e._v(", "),a("code",[e._v("-]")]),e._v(", "),a("code",[e._v("{+")]),e._v(", "),a("code",[e._v("+}")]),e._v(" by specifying "),a("code",[e._v("--word-diff=color")]),e._v(" or "),a("code",[e._v("--color-words")]),e._v(". This will only use color coding to mark the difference:")]),e._v(" "),a("p",[a("a",{attrs:{href:"http://i.stack.imgur.com/1vsUP.png",target:"_blank",rel:"noopener noreferrer"}},[a("img",{attrs:{src:"http://i.stack.imgur.com/1vsUP.png",alt:"Example of using git diff --color-words"}}),a("OutboundLink")],1)]),e._v(" "),a("h2",{attrs:{id:"using-meld-to-see-all-modifications-in-the-working-directory"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#using-meld-to-see-all-modifications-in-the-working-directory"}},[e._v("#")]),e._v(" Using meld to see all modifications in the working directory")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git difftool -t meld --dir-diff\n\n")])])]),a("p",[e._v("will show the working directory changes. Alternatively,")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git difftool -t meld --dir-diff [COMMIT_A] [COMMIT_B]\n\n")])])]),a("p",[e._v("will show the differences between 2 specific commits.")]),e._v(" "),a("h2",{attrs:{id:"show-differences-between-current-version-and-last-version"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#show-differences-between-current-version-and-last-version"}},[e._v("#")]),e._v(" Show differences between current version and last version")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff HEAD^ HEAD\n\n")])])]),a("p",[e._v("This will show the changes between the previous commit and the current commit.")]),e._v(" "),a("h2",{attrs:{id:"produce-a-patch-compatible-diff"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#produce-a-patch-compatible-diff"}},[e._v("#")]),e._v(" Produce a patch-compatible diff")]),e._v(" "),a("p",[e._v("Sometimes you just need a diff to apply using patch. The regular "),a("code",[e._v("git --diff")]),e._v(" does not work. Try this instead:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff --no-prefix > some_file.patch\n\n")])])]),a("p",[e._v("Then somewhere else you can reverse it:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("patch -p0 < some_file.patch\n\n")])])]),a("h2",{attrs:{id:"difference-between-two-commit-or-branch"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#difference-between-two-commit-or-branch"}},[e._v("#")]),e._v(" difference between two commit or branch")]),e._v(" "),a("p",[e._v("To view difference between two branch")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff ..\n\n")])])]),a("p",[e._v("To view difference between two branch")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff ..\n\n")])])]),a("p",[e._v("To view diff with current branch")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff \n\n")])])]),a("p",[e._v("To view summary of changes")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff --stat \n\n")])])]),a("p",[e._v("To view files that changed after a certain commit")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff --name-only \n\n")])])]),a("p",[e._v("To view files that are different than a branch")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff --name-only \n\n")])])]),a("p",[e._v("To view files that changed in a folder after a certain commit")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff --name-only \n\n")])])]),a("h2",{attrs:{id:"diff-utf-16-encoded-text-and-binary-plist-files"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#diff-utf-16-encoded-text-and-binary-plist-files"}},[e._v("#")]),e._v(" Diff UTF-16 encoded text and binary plist files")]),e._v(" "),a("p",[e._v("You can diff UTF-16 encoded files (localization strings file os iOS and macOS are examples) by specifying how git should diff these files.")]),e._v(" "),a("p",[e._v("Add the following to your "),a("code",[e._v("~/.gitconfig")]),e._v(" file.")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("[diff "),a("span",{pre:!0,attrs:{class:"token string"}},[e._v('"utf16"')]),e._v("]\ntextconv = "),a("span",{pre:!0,attrs:{class:"token string"}},[e._v('"iconv -f utf-16 -t utf-8"')]),e._v("\n\n")])])]),a("p",[a("code",[e._v("iconv")]),e._v(" is a program to "),a("a",{attrs:{href:"http://linux.die.net/man/1/iconv",target:"_blank",rel:"noopener noreferrer"}},[e._v("convert different encodings"),a("OutboundLink")],1),e._v(".")]),e._v(" "),a("p",[e._v("Then edit or create a "),a("code",[e._v(".gitattributes")]),e._v(" file in the root of the repository where you want to use it. Or just edit "),a("code",[e._v("~/.gitattributes")]),e._v(".")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("*.strings diff=utf16\n\n")])])]),a("p",[e._v("This will convert all files ending in "),a("code",[e._v(".strings")]),e._v(" before git diffs.")]),e._v(" "),a("p",[e._v("You can do similar things for other files, that can be converted to text.")]),e._v(" "),a("p",[e._v("For binary plist files you edit "),a("code",[e._v(".gitconfig")])]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("[diff "),a("span",{pre:!0,attrs:{class:"token string"}},[e._v('"plist"')]),e._v("]\ntextconv = plutil -convert xml1 -o -\n\n")])])]),a("p",[e._v("and "),a("code",[e._v(".gitattributes")])]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("*.plist diff=plist\n\n")])])]),a("h2",{attrs:{id:"viewing-a-three-way-merge-including-the-common-ancestor"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#viewing-a-three-way-merge-including-the-common-ancestor"}},[e._v("#")]),e._v(" Viewing a three-way merge including the common ancestor")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git config --global merge.conflictstyle diff3\n\n")])])]),a("p",[e._v("Sets the "),a("code",[e._v("diff3")]),e._v(" style as default: instead of the usual format in conflicted sections, showing the two files:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("<<<<<<< HEAD\nleft\n=======\nright\n>>>>>>> master\n\n")])])]),a("p",[e._v("it will include an additional section containing the original text (coming form the common ancestor):")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("<<<<<<< HEAD\nfirst\nsecond\n|||||||\nfirst\n=======\nlast\n>>>>>>> master\n\n")])])]),a("p",[e._v("This format makes it easier to understand merge-conflict, ie. in this case locally "),a("code",[e._v("second")]),e._v(" has been added, while remote changed "),a("code",[e._v("first")]),e._v(" to "),a("code",[e._v("last")]),e._v(", resolving to:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("last\nsecond\n\n")])])]),a("p",[e._v("The same resolution would have been much harder using the default:")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("<<<<<<< HEAD\nfirst\nsecond\n=======\nlast\n>>>>>>> master\n\n")])])]),a("h2",{attrs:{id:"show-changes-between-two-branches"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#show-changes-between-two-branches"}},[e._v("#")]),e._v(" Show changes between two branches")]),e._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[e._v("git diff branch1..branch2\n\n")])])]),a("h4",{attrs:{id:"syntax"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#syntax"}},[e._v("#")]),e._v(" Syntax")]),e._v(" "),a("ul",[a("li",[a("code",[e._v("git diff [options] [] [--] […​]")])]),e._v(" "),a("li",[a("code",[e._v("git diff [options] --cached [] [--] […​]")])]),e._v(" "),a("li",[a("code",[e._v("git diff [options] [--] […​]")])]),e._v(" "),a("li",[a("code",[e._v("git diff [options] ")])]),e._v(" "),a("li",[a("code",[e._v("git diff [options] [--no-index] [--] ")])])]),e._v(" "),a("h4",{attrs:{id:"parameters"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#parameters"}},[e._v("#")]),e._v(" Parameters")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th",[e._v("Parameter")]),e._v(" "),a("th",[e._v("Details")])])]),e._v(" "),a("tbody",[a("tr",[a("td",[e._v("-p, -u, --patch")]),e._v(" "),a("td",[e._v("Generate patch")])]),e._v(" "),a("tr",[a("td",[e._v("-s, --no-patch")]),e._v(" "),a("td",[e._v("Suppress diff output. Useful for commands like "),a("code",[e._v("git show")]),e._v(" that show the patch by default, or to cancel the effect of "),a("code",[e._v("--patch")])])]),e._v(" "),a("tr",[a("td",[e._v("--raw")]),e._v(" "),a("td",[e._v("Generate the diff in raw format")])]),e._v(" "),a("tr",[a("td",[e._v("--diff-algorithm=")]),e._v(" "),a("td",[e._v("Choose a diff algorithm. The variants are as follows: "),a("code",[e._v("myers")]),e._v(", "),a("code",[e._v("minimal")]),e._v(", "),a("code",[e._v("patience")]),e._v(", "),a("code",[e._v("histogram")])])]),e._v(" "),a("tr",[a("td",[e._v("--summary")]),e._v(" "),a("td",[e._v("Output a condensed summary of extended header information such as creations, renames and mode changes")])]),e._v(" "),a("tr",[a("td",[e._v("--name-only")]),e._v(" "),a("td",[e._v("Show only names of changed files")])]),e._v(" "),a("tr",[a("td",[e._v("--name-status")]),e._v(" "),a("td",[e._v("Show names and statuses of changed files The most common statuses are M (Modified), A (Added), and D (Deleted)")])]),e._v(" "),a("tr",[a("td",[e._v("--check")]),e._v(" "),a("td",[e._v("Warn if changes introduce conflict markers or whitespace errors. What are considered whitespace errors is controlled by "),a("code",[e._v("core.whitespace")]),e._v(" configuration. By default, trailing whitespaces (including lines that solely consist of whitespaces) and a space character that is immediately followed by a tab character inside the initial indent of the line are considered whitespace errors. Exits with non-zero status if problems are found. Not compatible with --exit-code")])]),e._v(" "),a("tr",[a("td",[e._v("--full-index")]),e._v(" "),a("td",[e._v('Instead of the first handful of characters, show the full pre- and post-image blob object names on the "index" line when generating patch format output')])]),e._v(" "),a("tr",[a("td",[e._v("--binary")]),e._v(" "),a("td",[e._v("In addition to "),a("code",[e._v("--full-index")]),e._v(", output a binary diff that can be applied with "),a("code",[e._v("git apply")])])]),e._v(" "),a("tr",[a("td",[e._v("-a, --text")]),e._v(" "),a("td",[e._v("Treat all files as text.")])]),e._v(" "),a("tr",[a("td",[e._v("--color")]),e._v(" "),a("td",[e._v("Set the color mode; i.e. use "),a("code",[e._v("--color=always")]),e._v(" if you would like to pipe a diff to less and keep git's coloring")])])])])])}),[],!1,null,null,null);t.default=i.exports}}]);