Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you just want to throw it away, while you're on your master branch:</p> <pre><code>git reset --hard HEAD^</code></pre> <p>This command will reset your master's HEAD pointer to the previous commit. (You could also say "HEAD~1", which means the same thing as HEAD^.) More generally, you can also reset your master to be the same as the server's:</p> <pre><code>git reset --hard origin/master</code></pre> <p>This will work regardless of the state of master (i.e. 5 commits ahead of origin, or 30 commits behind it). The <code>--hard</code> option in these commands means that the files in your working tree will also be reset along with the branch heads.</p> <p><b>Extra tips</b></p> <p>If you were in a similar situation where you actually wanted to keep your changes, you can always do:</p> <pre><code>git fetch # This grabs changes from the server without merging them git rebase origin</code></pre> <p>That will replay any work you have in master on top of the latest changes on the server.</p> <p>Yet another alternative would be to create a topic branch for your work on master:</p> <pre><code>git checkout -b newfeature</code></pre> <p>Then you could switch back to master (git checkout master) and use the first command I gave to rewind master back one commit. Remember, branches are really just convenient names for commits in your repository. For example, <code>master</code> is just a reference to the latest commit on that branch. You can move these references at will, and as you get more advanced with git, you'll find yourself doing it fairly often.</p> <p>I also recommend you get in the habit of running <code>gitk --all</code> whenever you're playing with branches, so you can visually see exactly what you're doing. When I was new to git, I ran this command <i>all the time</i>. I still do...</p>
    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