interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / Documentation / git-patch-id.adoc

117 lines · 3695 bytes Raw Blame History
1git-patch-id(1)
2===============
3
4NAME
5----
6git-patch-id - Compute unique IDs for patches
7
8SYNOPSIS
9--------
10[synopsis]
11git patch-id [--stable | --unstable | --verbatim]
12
13DESCRIPTION
14-----------
15Read patches from standard input and compute the patch IDs.
16
17A "patch ID" is nothing but a sum of SHA-1 of the file diffs associated with a
18patch, with line numbers ignored. As such, it's "reasonably stable", but at
19the 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
22The main usecase for this command is to look for likely duplicate commits.
23
24When dealing with `git diff-tree --patch` output, it takes advantage of
25the fact that the patch is prefixed with the object name of the
26commit, and outputs two 40-byte hexadecimal strings. The first
27string is the patch ID, and the second string is the commit ID.
28This can be used to make a mapping from patch ID to commit ID for a
29set or range of commits.
30
31OPTIONS
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+
38This 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+
60This 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+
69This is the default.
70
71EXAMPLES
72--------
73
74linkgit:git-cherry[1] shows what commits from a branch have patch ID
75equivalent commits in some upstream branch. But it only tells you
76whether such a commit exists or not. What if you wanted to know the
77relevant commits in the upstream? We can use this command to make a
78mapping between your branch and the upstream branch:
79
80----
81#!/bin/sh
82
83upstream="$1"
84branch="$2"
85test -z "$branch" && branch=HEAD
86limit="$3"
87if test -n "$limit"
88then
89 tail_opts="$limit".."$upstream"
90else
91 since=$(git log --format=%aI "$upstream".."$branch" | tail -1)
92 tail_opts=--since="$since"' '"$upstream"
93fi
94for_branch=$(mktemp)
95for_upstream=$(mktemp)
96
97git rev-list --no-merges "$upstream".."$branch" |
98 git diff-tree --patch --stdin |
99 git patch-id --stable | sort >"$for_branch"
100git rev-list --no-merges $tail_opts |
101 git diff-tree --patch --stdin |
102 git patch-id --stable | sort >"$for_upstream"
103join -a1 "$for_branch" "$for_upstream" | cut -d' ' -f2,3
104rm "$for_branch"
105rm "$for_upstream"
106----
107
108Now the first column shows the commit from your branch and the second
109column shows the patch ID equivalent commit, if it exists.
110
111SEE ALSO
112--------
113linkgit:git-cherry[1]
114
115GIT
116---
117Part of the linkgit:git[1] suite