3 # This script is used to produce git context diffs
7 # path old-file old-hash old-mode new-file new-hash new-mode
8 # 'path' is the git-tree-relative path of the file being diff'ed
12 This info is copied from the old wiki page on Working with git
:
14 Context diffs with Git
16 Copy git-external-diff into libexec
/git-core
/ of your git installation
17 and configure git to use that wrapper with
:
19 git config
[--global] diff.external git-external-diff
21 --global makes the configuration global
for your user
- otherwise it is
22 just configured
for the current repository.
24 For every
command which displays diffs
in some way you can use the
25 parameter
"--[no-]-ext-diff" to
enable respectively disable using the
26 external
diff command.
28 For the git
diff command --ext-diff is enabled by default
- for any
29 other
command like git log
-p or git format-patch it is not
!
31 This method should work on all platforms supported by git.
33 If you
do not want to configure the external wrapper permanently or you
34 want to overwrite it you can also invoke git like
:
36 export GIT_EXTERNAL_DIFF
=git-external-diff
37 git
diff --[no-
]ext-diff
39 Alternatively
, configure a git
alias in ~
/.gitconfig or .git
/config
:
42 cdiff
= !GIT_EXTERNAL_DIFF
=git-context-diff git
diff
46 new_hash
=$
(git hash-object
"$5")
49 [ "$old_hash" = "$new_hash" ] && exit 0
51 [ "$DIFF_OPTS" = "" ] && DIFF_OPTS
='-pcd'
53 echo "diff --git a/$1 b/$1"
54 echo "new file mode $7"
55 echo "index ${old_hash:0:7}..${new_hash:0:7}"
57 diff --label a
/"$1" --label b
/"$1" $DIFF_OPTS "$2" "$5"