Note that there are some explanatory texts on larger screens.

plurals
  1. POGit: How to Undo commit *and* revert to last branch
    primarykey
    data
    text
    <p>Uh oh... I mistakenly committed a pretty complex change (including subdirectory and files renames) without really knowing what I am doing (or what Git would be doing).</p> <p>I now want to undo everything such that:</p> <ol> <li>commit is completely reversed (as if it has never been done, perhaps removing it from history as well)</li> <li>Restore current working directory (where <code>.git</code> is) to a certain branch (last one will do for now).</li> </ol> <p>I found references to <a href="https://stackoverflow.com/questions/927358/git-undo-last-commit/927386#927386">git reset --soft</a> and <a href="https://stackoverflow.com/questions/2923055/how-to-move-a-branch-backwards-in-git/2923142#2923142">git reset --hard</a> but I have already proven to myself that I can do real damage by prematurely using a command without fully understanding it. :)</p> <p>I found the <a href="http://git-scm.com/docs/git-reset" rel="nofollow noreferrer">git reset man page</a> but I am still confused as to:</p> <ol> <li>What is <code>HEAD</code>?</li> <li>What is the difference between <code>HEAD</code> and <code>* master</code>?</li> <li>In my situation (see above) do I need to use <code>--soft</code>, <code>--hard</code> or other (3 more options)?</li> <li>Do I need to run another command (after doing <code>git reset</code>) to "finalize" the reversal?</li> </ol> <p><strong>UPDATE:</strong> After reading the answer below:</p> <ol> <li>Do I understand correctly that all I need to do in my situation is issue a single command <code>git reset --hard HEAD^</code>?</li> <li>How do I verify that reversal was performed correctly?</li> </ol>
    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.
 

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