Tutorial by Examples

git diff This will show the unstaged changes on the current branch from the commit before it. It will only show changes relative to the index, meaning it shows what you could add to the next commit, but haven't. To add (stage) these changes, you can use git add. If a file is staged, but was modi...
git diff --staged This will show the changes between the previous commit and the currently staged files. NOTE: You can also use the following commands to accomplish the same thing: git diff --cached Which is just a synonym for --staged or git status -v Which will trigger the verbose sett...
To show all staged and unstaged changes, use: git diff HEAD NOTE: You can also use the following command: git status -vv The difference being that the output of the latter will actually tell you which changes are staged for commit and which are not.
git diff 1234abc..6789def # old new E.g.: Show the changes made in the last 3 commits: git diff @~3..@ # HEAD -3 HEAD Note: the two dots (..) is optional, but adds clarity. This will show the textual difference between the commits, regardless of where they are in the tree.
git difftool -t meld --dir-diff will show the working directory changes. Alternatively, git difftool -t meld --dir-diff [COMMIT_A] [COMMIT_B] will show the differences between 2 specific commits.
git diff myfile.txt Shows the changes between the previous commit of the specified file (myfile.txt) and the locally-modified version that has not yet been staged. This also works for directories: git diff documentation The above shows the changes between the previous commit of all files in ...
git diff [HEAD|--staged...] --word-diff Rather than displaying lines changed, this will display differences within lines. For example, rather than: -Hello world +Hello world! Where the whole line is marked as changed, word-diff alters the output to: Hello [-world-]{+world!+} You can omit...
git config --global merge.conflictstyle diff3 Sets the diff3 style as default: instead of the usual format in conflicted sections, showing the two files: <<<<<<< HEAD left ======= right >>>>>>> master it will include an additional section containi...
git diff HEAD^ HEAD This will show the changes between the previous commit and the current commit.
You can diff UTF-16 encoded files (localization strings file os iOS and macOS are examples) by specifying how git should diff these files. Add the following to your ~/.gitconfig file. [diff "utf16"] textconv = "iconv -f utf-16 -t utf-8" iconv is a program to convert differe...
Show the changes between the tip of new and the tip of original: git diff original new # equivalent to original..new Show all changes on new since it branched from original: git diff original...new # equivalent to $(git merge-base original new)..new Using only one parameter such as ...
git diff branch1..branch2
Sometimes you just need a diff to apply using patch. The regular git --diff does not work. Try this instead: git diff --no-prefix > some_file.patch Then somewhere else you can reverse it: patch -p0 < some_file.patch
To view difference between two branch git diff <branch1>..<branch2> To view difference between two branch git diff <commitId1>..<commitId2> To view diff with current branch git diff <branch/commitId> To view summary of changes git diff --stat <branch/com...

Page 1 of 1