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

<sect2 lang="en" id="git-revert(1)">
    <title>git-revert(1)</title>
    <date>2024-07-02</date>
<revhistory><revision><date>2024-07-02</date></revision></revhistory>
<indexterm>
<primary>git-revert(1)</primary>
</indexterm>
<simplesect id="git-revert(1)__name">
<title>NAME</title>
<simpara>git-revert - Revert some existing commits</simpara>
</simplesect>
<simplesect id="git-revert(1)__synopsis">
<title>SYNOPSIS</title>
<blockquote>
<literallayout><emphasis>git revert</emphasis> [--[no-]edit] [-n] [-m &lt;parent-number&gt;] [-s] [-S[&lt;keyid&gt;]] &lt;commit&gt;&#8230;
<emphasis>git revert</emphasis> (--continue | --skip | --abort | --quit)</literallayout>
</blockquote>
</simplesect>
<simplesect id="git-revert(1)__description">
<title>DESCRIPTION</title>
<simpara>Given one or more existing commits, revert the changes that the
related patches introduce, and record some new commits that record
them.  This requires your working tree to be clean (no modifications
from the HEAD commit).</simpara>
<simpara>Note: <emphasis>git revert</emphasis> is used to record some new commits to reverse the
effect of some earlier commits (often only a faulty one).  If you want to
throw away all uncommitted changes in your working directory, you
should see <xref linkend="git-reset(1)" />, particularly the <emphasis>--hard</emphasis> option.  If
you want to extract specific files as they were in another commit, you
should see <xref linkend="git-restore(1)" />, specifically the <emphasis>--source</emphasis>
option. Take care with these alternatives as
both will discard uncommitted changes in your working directory.</simpara>
<simpara>See "Reset, restore and revert" in <xref linkend="git(1)" /> for the differences
between the three commands.</simpara>
</simplesect>
<simplesect id="git-revert(1)__options">
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term>
&lt;commit&gt;&#8230;
</term>
<listitem>
<simpara>
        Commits to revert.
        For a more complete list of ways to spell commit names, see
        <xref linkend="gitrevisions(7)" />.
        Sets of commits can also be given but no traversal is done by
        default, see <xref linkend="git-rev-list(1)" /> and its <emphasis>--no-walk</emphasis>
        option.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-e
</term>
<term>
--edit
</term>
<listitem>
<simpara>
        With this option, <emphasis>git revert</emphasis> will let you edit the commit
        message prior to committing the revert. This is the default if
        you run the command from a terminal.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-m parent-number
</term>
<term>
--mainline parent-number
</term>
<listitem>
<simpara>
        Usually you cannot revert a merge because you do not know which
        side of the merge should be considered the mainline.  This
        option specifies the parent number (starting from 1) of
        the mainline and allows revert to reverse the change
        relative to the specified parent.
</simpara>
<simpara>Reverting a merge commit declares that you will never want the tree changes
brought in by the merge.  As a result, later merges will only bring in tree
changes introduced by commits that are not ancestors of the previously
reverted merge.  This may or may not be what you want.</simpara>
<simpara>See the <ulink url="https://www.kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.html"><citetitle>revert-a-faulty-merge How-To</citetitle></ulink> for
more details.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-edit
</term>
<listitem>
<simpara>
        With this option, <emphasis>git revert</emphasis> will not start the commit
        message editor.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--cleanup=&lt;mode&gt;
</term>
<listitem>
<simpara>
        This option determines how the commit message will be cleaned up before
        being passed on to the commit machinery. See <xref linkend="git-commit(1)" /> for more
        details. In particular, if the <emphasis>&lt;mode&gt;</emphasis> is given a value of <emphasis>scissors</emphasis>,
        scissors will be appended to <emphasis>MERGE_MSG</emphasis> before being passed on in the case
        of a conflict.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-n
</term>
<term>
--no-commit
</term>
<listitem>
<simpara>
        Usually the command automatically creates some commits with
        commit log messages stating which commits were
        reverted.  This flag applies the changes necessary
        to revert the named commits to your working tree
        and the index, but does not make the commits.  In addition,
        when this option is used, your index does not have to match
        the HEAD commit.  The revert is done against the
        beginning state of your index.
</simpara>
<simpara>This is useful when reverting more than one commits'
effect to your index in a row.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-S[&lt;keyid&gt;]
</term>
<term>
--gpg-sign[=&lt;keyid&gt;]
</term>
<term>
--no-gpg-sign
</term>
<listitem>
<simpara>
        GPG-sign commits. The <emphasis>keyid</emphasis> argument is optional and
        defaults to the committer identity; if specified, it must be
        stuck to the option without a space. <emphasis>--no-gpg-sign</emphasis> is useful to
        countermand both <emphasis>commit.gpgSign</emphasis> configuration variable, and
        earlier <emphasis>--gpg-sign</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-s
</term>
<term>
--signoff
</term>
<listitem>
<simpara>
        Add a <emphasis>Signed-off-by</emphasis> trailer at the end of the commit message.
        See the signoff option in <xref linkend="git-commit(1)" /> for more information.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--strategy=&lt;strategy&gt;
</term>
<listitem>
<simpara>
        Use the given merge strategy.  Should only be used once.
        See the MERGE STRATEGIES section in <xref linkend="git-merge(1)" />
        for details.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-X&lt;option&gt;
</term>
<term>
--strategy-option=&lt;option&gt;
</term>
<listitem>
<simpara>
        Pass the merge strategy-specific option through to the
        merge strategy.  See <xref linkend="git-merge(1)" /> for details.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--rerere-autoupdate
</term>
<term>
--no-rerere-autoupdate
</term>
<listitem>
<simpara>
        After the rerere mechanism reuses a recorded resolution on
        the current conflict to update the files in the working
        tree, allow it to also update the index with the result of
        resolution.  <emphasis>--no-rerere-autoupdate</emphasis> is a good way to
        double-check what <emphasis>rerere</emphasis> did and catch potential
        mismerges, before committing the result to the index with a
        separate <emphasis>git add</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--reference
</term>
<listitem>
<simpara>
        Instead of starting the body of the log message with "This
        reverts &lt;full-object-name-of-the-commit-being-reverted&gt;.",
        refer to the commit using "--pretty=reference" format
        (cf. <xref linkend="git-log(1)" />).  The <emphasis>revert.reference</emphasis>
        configuration variable can be used to enable this option by
        default.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="git-revert(1)__sequencer_subcommands">
<title>SEQUENCER SUBCOMMANDS</title>
<variablelist>
<varlistentry>
<term>
--continue
</term>
<listitem>
<simpara>
        Continue the operation in progress using the information in
        <emphasis>.git/sequencer</emphasis>.  Can be used to continue after resolving
        conflicts in a failed cherry-pick or revert.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--skip
</term>
<listitem>
<simpara>
        Skip the current commit and continue with the rest of the
        sequence.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--quit
</term>
<listitem>
<simpara>
        Forget about the current operation in progress.  Can be used
        to clear the sequencer state after a failed cherry-pick or
        revert.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--abort
</term>
<listitem>
<simpara>
        Cancel the operation and return to the pre-sequence state.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="git-revert(1)__examples">
<title>EXAMPLES</title>
<variablelist>
<varlistentry>
<term>
<emphasis>git revert HEAD~3</emphasis>
</term>
<listitem>
<simpara>
        Revert the changes specified by the fourth last commit in HEAD
        and create a new commit with the reverted changes.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis>git revert -n master~5..master~2</emphasis>
</term>
<listitem>
<simpara>
        Revert the changes done by commits from the fifth last commit
        in master (included) to the third last commit in master
        (included), but do not create any commit with the reverted
        changes. The revert only modifies the working tree and the
        index.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="git-revert(1)__discussion">
<title>DISCUSSION</title>
<simpara>While git creates a basic commit message automatically, it is
<emphasis>strongly</emphasis> recommended to explain why the original commit is being
reverted.
In addition, repeatedly reverting reverts will result in increasingly
unwieldy subject lines, for example <emphasis>Reapply "Reapply "&lt;original-subject&gt;""</emphasis>.
Please consider rewording these to be shorter and more unique.</simpara>
</simplesect>
<simplesect id="git-revert(1)__configuration">
<title>CONFIGURATION</title>
<simpara>Everything below this line in this section is selectively included
from the <xref linkend="git-config(1)" /> documentation. The content is the same
as what's found there:</simpara>
<variablelist>
<varlistentry>
<term>
revert.reference
</term>
<listitem>
<simpara>
        Setting this variable to true makes <emphasis>git revert</emphasis> behave
        as if the <emphasis>--reference</emphasis> option is given.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="git-revert(1)__see_also">
<title>SEE ALSO</title>
<simpara><xref linkend="git-cherry-pick(1)" /></simpara>
</simplesect>
<simplesect id="git-revert(1)__git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
</simplesect>
</sect2>
