Raw
1 git-patch-id(1)
2 ===============
3
4 NAME
5 ----
6 git-patch-id - Compute unique IDs for patches
7
8 SYNOPSIS
9 --------
10 [synopsis]
11 git patch-id [--stable | --unstable | --verbatim]
12
13 DESCRIPTION
14 -----------
15 Read patches from standard input and compute the patch IDs.
16
17 A "patch ID" is nothing but a sum of SHA-1 of the file diffs associated with a
18 patch, with line numbers ignored. As such, it's "reasonably stable", but at
19 the same time also reasonably unique, i.e., two patches that have the same
20 "patch ID" are almost guaranteed to be the same thing.
21
22 The main usecase for this command is to look for likely duplicate commits.
23
24 When dealing with `git diff-tree --patch` output, it takes advantage of
25 the fact that the patch is prefixed with the object name of the
26 commit, and outputs two 40-byte hexadecimal strings. The first
27 string is the patch ID, and the second string is the commit ID.
28 This can be used to make a mapping from patch ID to commit ID for a
29 set or range of commits.
30
31 OPTIONS
32 -------
33
34 `--verbatim`::
35 Calculate the patch ID of the input as it is given, do not strip
36 any whitespace. Implies `--stable` and forbids `--unstable`.
37 +
38 This is the default if `patchid.verbatim` is `true`.
39
40 `--stable`::
41 Use a "stable" sum of hashes as the patch ID. With this option:
42 +
43 --
44 - Reordering file diffs that make up a patch does not affect the ID.
45 In particular, two patches produced by comparing the same two trees
46 with two different settings for `-O<orderfile>` result in the same
47 patch ID signature, thereby allowing the computed result to be used
48 as a key to index some meta-information about the change between
49 the two trees.
50
51 - The result is different from the value produced by Git 1.9 and older
52 or produced when an "unstable" hash (see `--unstable` below) is
53 configured - even when used on a diff output taken without any use
54 of `-O<orderfile>`, thereby making existing databases storing such
55 "unstable" or historical patch IDs unusable.
56
57 - All whitespace within the patch is ignored and does not affect the ID.
58 --
59 +
60 This is the default if `patchid.stable` is set to `true`.
61
62 `--unstable`::
63 Use an "unstable" hash as the patch ID. With this option,
64 the result produced is compatible with the patch ID value produced
65 by Git 1.9 and older and whitespace is ignored. Users with pre-existing
66 databases storing patch IDs produced by Git 1.9 and older (who do not deal
67 with reordered patches) may want to use this option.
68 +
69 This is the default.
70
71 EXAMPLES
72 --------
73
74 linkgit:git-cherry[1] shows what commits from a branch have patch ID
75 equivalent commits in some upstream branch. But it only tells you
76 whether such a commit exists or not. What if you wanted to know the
77 relevant commits in the upstream? We can use this command to make a
78 mapping between your branch and the upstream branch:
79
80 ----
81 #!/bin/sh
82
83 upstream="$1"
84 branch="$2"
85 test -z "$branch" && branch=HEAD
86 limit="$3"
87 if test -n "$limit"
88 then
89 tail_opts="$limit".."$upstream"
90 else
91 since=$(git log --format=%aI "$upstream".."$branch" | tail -1)
92 tail_opts=--since="$since"' '"$upstream"
93 fi
94 for_branch=$(mktemp)
95 for_upstream=$(mktemp)
96
97 git rev-list --no-merges "$upstream".."$branch" |
98 git diff-tree --patch --stdin |
99 git patch-id --stable | sort >"$for_branch"
100 git rev-list --no-merges $tail_opts |
101 git diff-tree --patch --stdin |
102 git patch-id --stable | sort >"$for_upstream"
103 join -a1 "$for_branch" "$for_upstream" | cut -d' ' -f2,3
104 rm "$for_branch"
105 rm "$for_upstream"
106 ----
107
108 Now the first column shows the commit from your branch and the second
109 column shows the patch ID equivalent commit, if it exists.
110
111 SEE ALSO
112 --------
113 linkgit:git-cherry[1]
114
115 GIT
116 ---
117 Part of the linkgit:git[1] suite