Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Update:</h2> <p>Because of changes to how tracking branches are created and pushed I no longer recommend renaming branches. This is what I recommend now:</p> <p>Make a copy of the branch at its current state:</p> <pre><code>git branch crazyexperiment </code></pre> <p>(The <a href="http://git-scm.com/docs/git-branch" rel="noreferrer"><code>git branch &lt;name&gt;</code></a> command will leave you with your current branch still checked out.)</p> <p>Reset your current branch to your desired commit with <a href="http://git-scm.com/docs/git-reset" rel="noreferrer"><code>git reset</code></a>:</p> <pre><code>git reset --hard c2e7af2b51 </code></pre> <p>(Replace <code>c2e7af2b51</code> with the commit that you want to go back to.)</p> <p>When you decide that your crazy experiment branch doesn't contain anything useful, you can delete it with:</p> <pre><code>git branch -D crazyexperiment </code></pre> <p>It's always nice when you're starting out with history-modifying git commands (reset, rebase) to create backup branches before you run them. Eventually once you're comfortable you won't find it necessary. If you do modify your history in a way that you don't want and haven't created a backup branch, look into <a href="http://git-scm.com/docs/git-reflog" rel="noreferrer"><code>git reflog</code></a>. Git keeps commits around for quite a while even if there are no branches or tags pointing to them.</p> <h2>Original answer:</h2> <p>A slightly less scary way to do this than the <code>git reset --hard</code> method is to create a new branch. Let's assume that you're on the <code>master</code> branch and the commit you want to go back to is <code>c2e7af2b51</code>.</p> <p>Rename your current master branch:</p> <pre><code>git branch -m crazyexperiment </code></pre> <p>Check out your good commit:</p> <pre><code>git checkout c2e7af2b51 </code></pre> <p>Make your new master branch here:</p> <pre><code>git checkout -b master </code></pre> <p>Now you still have your crazy experiment around if you want to look at it later, but your master branch is back at your last known good point, ready to be added to. If you really want to throw away your experiment, you can use:</p> <pre><code>git branch -D crazyexperiment </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. 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