<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">

<sect2 lang="en" id="git-patch-id(1)">
    <title>git-patch-id(1)</title>
    <date>2024-07-02</date>
<revhistory><revision><date>2024-07-02</date></revision></revhistory>
<indexterm>
<primary>git-patch-id(1)</primary>
</indexterm>
<simplesect id="git-patch-id(1)__name">
<title>NAME</title>
<simpara>git-patch-id - Compute unique ID for a patch</simpara>
</simplesect>
<simplesect id="git-patch-id(1)__synopsis">
<title>SYNOPSIS</title>
<blockquote>
<literallayout><emphasis>git patch-id</emphasis> [--stable | --unstable | --verbatim]</literallayout>
</blockquote>
</simplesect>
<simplesect id="git-patch-id(1)__description">
<title>DESCRIPTION</title>
<simpara>Read a patch from the standard input and compute the patch ID for it.</simpara>
<simpara>A "patch ID" is nothing but a sum of SHA-1 of the file diffs associated with a
patch, with line numbers ignored.  As such, it's "reasonably stable", but at
the same time also reasonably unique, i.e., two patches that have the same
"patch ID" are almost guaranteed to be the same thing.</simpara>
<simpara>The main usecase for this command is to look for likely duplicate commits.</simpara>
<simpara>When dealing with <emphasis>git diff-tree</emphasis> output, it takes advantage of
the fact that the patch is prefixed with the object name of the
commit, and outputs two 40-byte hexadecimal strings.  The first
string is the patch ID, and the second string is the commit ID.
This can be used to make a mapping from patch ID to commit ID.</simpara>
</simplesect>
<simplesect id="git-patch-id(1)__options">
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term>
--verbatim
</term>
<listitem>
<simpara>
        Calculate the patch-id of the input as it is given, do not strip
        any whitespace.
</simpara>
<literallayout class="monospaced">This is the default if patchid.verbatim is true.</literallayout>
</listitem>
</varlistentry>
<varlistentry>
<term>
--stable
</term>
<listitem>
<simpara>
        Use a "stable" sum of hashes as the patch ID. With this option:
</simpara>
<itemizedlist>
<listitem>
<simpara>
Reordering file diffs that make up a patch does not affect the ID.
           In particular, two patches produced by comparing the same two trees
           with two different settings for "-O&lt;orderfile&gt;" result in the same
           patch ID signature, thereby allowing the computed result to be used
           as a key to index some meta-information about the change between
           the two trees;
</simpara>
</listitem>
<listitem>
<simpara>
Result is different from the value produced by git 1.9 and older
           or produced when an "unstable" hash (see --unstable below) is
           configured - even when used on a diff output taken without any use
           of "-O&lt;orderfile&gt;", thereby making existing databases storing such
           "unstable" or historical patch-ids unusable.
</simpara>
</listitem>
<listitem>
<simpara>
All whitespace within the patch is ignored and does not affect the id.
</simpara>
<literallayout class="monospaced">This is the default if patchid.stable is set to true.</literallayout>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>
--unstable
</term>
<listitem>
<simpara>
        Use an "unstable" hash as the patch ID. With this option,
        the result produced is compatible with the patch-id value produced
        by git 1.9 and older and whitespace is ignored.  Users with pre-existing
        databases storing patch-ids produced by git 1.9 and older (who do not deal
        with reordered patches) may want to use this option.
</simpara>
<literallayout class="monospaced">This is the default.</literallayout>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="git-patch-id(1)__git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
</simplesect>
</sect2>
