Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>Expanding what I wrote in a comment</em></p> <p>The general rule is that you should not rewrite (change) history that you have published, because somebody might have based their work on it. If you rewrite (change) history, you would make problems with merging their changes and with updating for them.</p> <p>So the solution is to create a <em>new commit</em> which <strong>reverts changes</strong> that you want to get rid of. You can do this using <a href="http://www.kernel.org/pub/software/scm/git/docs/git-revert.html" rel="noreferrer" title="git-revert(1) Manual Page - Revert an existing commit">git revert</a> command.</p> <p>You have the following situation:</p> <pre> A &lt;-- B &lt;-- C &lt;-- D &lt;-- master &lt;-- HEAD </pre> <p>(arrows here refers to the direction of the pointer: the "parent" reference in the case of commits, the top commit in the case of branch head (branch ref), and the name of branch in the case of HEAD reference).</p> <p>What you need to create is the following:</p> <pre> A &lt;-- B &lt;-- C &lt;-- D &lt;-- [(BCD)^-1] &lt;-- master &lt;-- HEAD </pre> <p>where "[(BCD)^-1]" means the commit that reverts changes in commits B, C, D. Mathematics tells us that (BCD)^-1 = D^-1 C^-1 B^-1, so you can get the required situation using the following commands:</p> <pre><code>$ git revert --no-commit D $ git revert --no-commit C $ git revert --no-commit B $ git commit -m "the commit message" </code></pre> <hr> <p>Alternate solution would be to <a href="http://git-scm.com/docs/git-checkout" rel="noreferrer" title="git-checkout(1) Manual Page - Checkout a branch or paths to the working tree">checkout</a> <em>contents</em> of commit A, and commit this state:</p> <pre><code>$ git checkout -f A -- . $ git commit -a </code></pre> <p>Then you would have the following situation:</p> <pre> A &lt;-- B &lt;-- C &lt;-- D &lt;-- A' &lt;-- master &lt;-- HEAD </pre> <p>The commit A' has the same contents as commit A, but is a different commit (commit message, parents, commit date).</p> <p>The <a href="https://stackoverflow.com/questions/1463340/revert-multiple-git-commits/1463390#comment1312779_1463390">solution by Jeff Ferland, modified by Charles Bailey</a> builds upon the same idea, but uses <a href="https://www.kernel.org/pub/software/scm/git/docs/git-reset.html" rel="noreferrer" title="git-reset(1) Manual Page - Reset current HEAD to the specified state">git reset</a>:</p> <pre><code>$ git reset --hard A $ git reset --soft @{1} # (or ORIG_HEAD), which is D $ git commit </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload