User Tools

Site Tools


git_diff

This is an old revision of the document!


A PCRE internal error occured. This might be caused by a faulty plugin

===== Overview ===== The basic usage of ''git diff'' which, in general, compares two //tree-ish objects//, where a tree-ish object is one of: * a specific commit (HEAD, SHA-1 hash, tag or branch name) * the working tree * the index ===== SYNOPSIS ===== <code> git diff [<options>] [<commit>] [--] [<path>...] git diff [<options>] --cached [<commit>] [--] [<path>...] git diff [<options>] <commit> <commit> [--] [<path>...] git diff [<options>] <blob> <blob> git diff [<options>] --no-index [--] <path> <path> </code> ===== Output of "git diff" ===== Default output format is the patch-style difference to change from the first argument to the second argument: <code> $ git diff diff --git a/Makefile b/Makefile index 96c5335e7ee4..71913214b18c 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +junk here + # SPDX-License-Identifier: GPL-2.0 VERSION = 5 PATCHLEVEL = 0 $ </code> ===== Basic "git diff" ===== The tree-ish objects in play: * HEAD: The most recent commit on the current branch * deadbeef: The SHA-1 hash of an arbitrary commit * bugfix42: A current development branch * v1.0: A historical tag somewhere in history Most common comparisons: <code> $ git diff [working tree vs index] $ git diff --cached/--staged [index vs HEAD] $ git diff HEAD [working tree vs HEAD] </code> With one argument, compare working tree to that argument: <code> $ git diff HEAD [working tree vs HEAD, as above] $ git diff deadbeef [working tree versus commit deadbeef] $ git diff bugfix42 [working tree versus branch bugfix42] $ git diff v1.0 [working tree versus tag v1.0] </code> With ''--cached'' (or ''%%--%%staged''), as above but with index: <code> $ git diff --cached HEAD $ git diff --cached deadbeef $ git diff --cached bugfix42 $ git diff --cached v1.0 </code> Comparing two explicit commits in various ways: <code> $ git diff v1.0 v2.0 $ git diff master bugfix42 $ git diff HEAD^ HEAD $ git diff deadbeef master </code> ===== Path limiting ===== Compare only //part// of the tree-ish objects: <code> $ git diff v4.19 v4.20 -- scripts/dtc/ diff --git a/scripts/dtc/Makefile b/scripts/dtc/Makefile index 1c943e03eaf2..056d5da6c477 100644 --- a/scripts/dtc/Makefile +++ b/scripts/dtc/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 # scripts/dtc makefile -hostprogs-y := dtc +hostprogs-$(CONFIG_DTC) := dtc always := $(hostprogs-y) dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \ ... lots of output snipped ... </code> ===== Popular options with git diff ===== Sometimes you don't need to see all of the output: <code> $ git diff v4.19 v4.20 -- scripts/dtc/ | wc -l 2097 $ </code> ==== --stat ==== <code> $ git diff v4.19 v4.20 --stat -- scripts/ scripts/dtc/checks.c | 291 +++++++++++++++++++++++- scripts/dtc/dtc-lexer.lex.c_shipped | 10 +- scripts/dtc/dtc-parser.tab.c_shipped | 430 ++++++++++++++++++----------------- scripts/dtc/dtc-parser.y | 20 +- scripts/dtc/dtc.c | 2 +- scripts/dtc/dtc.h | 3 + scripts/dtc/libfdt/fdt_addresses.c | 96 ++++++++ scripts/dtc/libfdt/fdt_empty_tree.c | 1 - scripts/dtc/libfdt/fdt_overlay.c | 861 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/dtc/libfdt/fdt_ro.c | 4 +- scripts/dtc/libfdt/fdt_rw.c | 24 +- scripts/dtc/libfdt/fdt_sw.c | 16 +- scripts/dtc/libfdt/fdt_wip.c | 4 +- scripts/dtc/libfdt/libfdt.h | 47 ++++ scripts/dtc/livetree.c | 31 ++- scripts/dtc/update-dtc-source.sh | 4 +- scripts/dtc/version_gen.h | 2 +- 17 files changed, 1615 insertions(+), 231 deletions(-) $ </code> ==== --name-only ==== <code> $ git diff v4.14 v4.15 --name-only -- scripts/dtc/ scripts/dtc/checks.c scripts/dtc/dtc-lexer.lex.c_shipped scripts/dtc/dtc-parser.tab.c_shipped scripts/dtc/dtc-parser.y scripts/dtc/dtc.c scripts/dtc/dtc.h scripts/dtc/libfdt/fdt_addresses.c scripts/dtc/libfdt/fdt_empty_tree.c scripts/dtc/libfdt/fdt_overlay.c scripts/dtc/libfdt/fdt_ro.c scripts/dtc/libfdt/fdt_rw.c scripts/dtc/libfdt/fdt_sw.c scripts/dtc/libfdt/fdt_wip.c scripts/dtc/libfdt/libfdt.h scripts/dtc/livetree.c scripts/dtc/update-dtc-source.sh scripts/dtc/version_gen.h $ </code> ===== Comparing two arbitrary files ===== General form: <code> $ git diff <commit1>:<file2> <commit2>:<file2> </code> For example, after a rename: <code> $ git diff v4.18:Makefile v4.19:makefile </code> ===== Whitespace issues ===== Just scratching the surface: <code> --ignore-cr-at-eol Ignore carrige-return at the end of line when doing a comparison. --ignore-space-at-eol Ignore changes in whitespace at EOL. -b, --ignore-space-change Ignore changes in amount of whitespace. This ignores whitespace at line end, and considers all other sequences of one or more whitespace characters to be equivalent. -w, --ignore-all-space Ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none. --ignore-blank-lines Ignore changes whose lines are all blank. </code>

git_diff.1550920126.txt.gz · Last modified: 2019/02/23 11:08 by rpjday