Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

finished the undo chapter

  • Loading branch information...
commit b6bce8f9364acec42d1cd10e6e1fa36be481db0b 1 parent 08159e2
@schacon schacon authored
View
14 episodes.yaml
@@ -39,12 +39,7 @@ episodes:
projects or specific files within your project.
- section: Intermediate
- values:
- - name: Undoing
- page: undoing
- desc: Revert, unmodify or unstage a file or project state
- at any point.
-
+ values:
- name: Distributed Workflows
desc: Fetch, merge, pull and push between multiple remote
repositories.
@@ -63,7 +58,12 @@ episodes:
- name: Interactive Adding
desc: Stage and unstage changes to files or partial files
with an interactive Git tool.
-
+
+ - name: Undoing
+ page: undoing
+ desc: Revert, unmodify or unstage a file or project state
+ at any point.
+
- name: Amending Commits
desc: Change the latest commit message, or redo the last commit
by adding or removing files from it.
View
BIN  images/undo/step1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  images/undo/step2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  images/undo/step3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  images/undo/topic2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  images/undo/topic3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  images/undo/topic4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
2  index.html
@@ -67,7 +67,7 @@
<hr/>
</div>
- <div class="span-5"><h2>Beginner</h2><div class='episode'><b><a href="p/intro.html">Introduction To Git</a></b><p>What Git is, why you would want to use it and where to get it and learn about it.</p></div><div class='episode'><b><a href="p/setup.html">Setup and Initialization</a></b><p>Setup your Git environment, then create a new Git repository and clone an existing one.</p></div><div class='episode'><b><a href="p/normal.html">Normal Workflow</a></b><p>Syncronize with a remote repository, make changes, then stage and commit them.</p></div><div class='episode'><b><a href="p/branching.html">Basic Branching and Merging</a></b><p>Create and work on topic and long running branches, merge between them and delete them.</p></div><div class='episode'><b><a href="p/tagging.html">Git Tagging</a></b><p>Create signed, unsigned or lightweight tags to permanantly mark important points in your project history.</p></div><div class='episode'><b><a href="p/log.html">Git Log</a></b><p>Browse your project history, find specific commits and visualize the branching and merging actions.</p></div><div class='episode'><b><a href="p/diff.html">Git Diff</a></b><p>Show differences between different versions of your projects or specific files within your project.</p></div></div><div class="span-5"><h2>Intermediate</h2><div class='episode'><b><a href="p/undoing.html">Undoing</a></b><p>Revert, unmodify or unstage a file or project state at any point.</p></div><div class='episode'><b>Distributed Workflows</b><p>Fetch, merge, pull and push between multiple remote repositories.</p></div><div class='episode'><b><a href="p/rebasing.html">Rebasing</a></b><p>Replay changes from one branch onto another branch to preserve a linear history.</p></div><div class='episode'><b><a href="p/stashing.html">Stashing</a></b><p>Temporarily save changes to your working directory and staging area without having to commit, then reapply the changes later.</p></div><div class='episode'><b>Interactive Adding</b><p>Stage and unstage changes to files or partial files with an interactive Git tool.</p></div><div class='episode'><b>Amending Commits</b><p>Change the latest commit message, or redo the last commit by adding or removing files from it.</p></div><div class='episode'><b>Interactive Rebasing</b><p>Rebase multiple files interactively, squashing, reordering or amending commits in between.</p></div><div class='episode'><b>Customizing Git</b><p>Setup aliases for common commands and other personal options in Git - autocompletion, bash branch, colors and more.</p></div></div><div class="span-5"><h2>Advanced</h2><div class='episode'><b>Filter Branch</b><p>Modify large sections of your commit history at once, changing emails, names or files globally.</p></div><div class='episode'><b>Maintaining Git</b><p>Learn the fsck and gc commands to diagnose problems and keep your repository small.</p></div><div class='episode'><b>The Git Reflog</b><p>Browse the history of your local references even if they're not referenced anywhere else anymore.</p></div><div class='episode'><b>Data Recovery</b><p>Find lost commits or branches and restore them, or recover from partial database corruption.</p></div><div class='episode'><b>Git Hooks</b><p>Learn the client and server side pre and post action hooks and some useful example scripts to use with them.</p></div><div class='episode'><b>Revision Selection</b><p>Selecting individual commits or ranges of commits using helpful Git shorthands.</p></div><div class='episode'><b>Git Internals</b><p>Explore the internal workings of Git - the different object types and how to view the raw data via several useful plumbing commands.</p></div><div class='episode'><b>Git Submodules</b><p>Submodule usage and other tips for keeping subprojects in your Git repository.</p></div></div><div class="span-6 last"><h2>Special Interest</h2><div class='episode'><b>Git and Windows - General</b><p>Install and use Git on a Windows environment using the default mSysGit tools.</p></div><div class='episode'><b>Git and Windows - Extensions</b><p>Installing and using the Git Extensions shell extensions tools on Windows.</p></div><div class='episode'><b>Git and Subversion</b><p>Using the git-svn client with a Subversion server. Specifically for existing SVN users, how Git is a better Subversion client than Subversion.</p></div><div class='episode'><b>Migrating from Subversion</b><p>Ready to move your project from Subversion? A few ways to do the migration, from hosted services to really custom methods.</p></div><div class='episode'><b>Git and Textmate</b><p>Using Git and GitHub from Textmate using the TM Git bundle.</p></div><div class='episode'><b>Git and Capistrano</b><p>Deploying Git projects using the Capistrano deployment tool, including how to deploy from GitHub.</p></div></div>
+ <div class="span-5"><h2>Beginner</h2><div class='episode'><b><a href="p/intro.html">Introduction To Git</a></b><p>What Git is, why you would want to use it and where to get it and learn about it.</p></div><div class='episode'><b><a href="p/setup.html">Setup and Initialization</a></b><p>Setup your Git environment, then create a new Git repository and clone an existing one.</p></div><div class='episode'><b><a href="p/normal.html">Normal Workflow</a></b><p>Syncronize with a remote repository, make changes, then stage and commit them.</p></div><div class='episode'><b><a href="p/branching.html">Basic Branching and Merging</a></b><p>Create and work on topic and long running branches, merge between them and delete them.</p></div><div class='episode'><b><a href="p/tagging.html">Git Tagging</a></b><p>Create signed, unsigned or lightweight tags to permanantly mark important points in your project history.</p></div><div class='episode'><b><a href="p/log.html">Git Log</a></b><p>Browse your project history, find specific commits and visualize the branching and merging actions.</p></div><div class='episode'><b><a href="p/diff.html">Git Diff</a></b><p>Show differences between different versions of your projects or specific files within your project.</p></div></div><div class="span-5"><h2>Intermediate</h2><div class='episode'><b>Distributed Workflows</b><p>Fetch, merge, pull and push between multiple remote repositories.</p></div><div class='episode'><b><a href="p/rebasing.html">Rebasing</a></b><p>Replay changes from one branch onto another branch to preserve a linear history.</p></div><div class='episode'><b><a href="p/stashing.html">Stashing</a></b><p>Temporarily save changes to your working directory and staging area without having to commit, then reapply the changes later.</p></div><div class='episode'><b>Interactive Adding</b><p>Stage and unstage changes to files or partial files with an interactive Git tool.</p></div><div class='episode'><b><a href="p/undoing.html">Undoing</a></b><p>Revert, unmodify or unstage a file or project state at any point.</p></div><div class='episode'><b>Amending Commits</b><p>Change the latest commit message, or redo the last commit by adding or removing files from it.</p></div><div class='episode'><b>Interactive Rebasing</b><p>Rebase multiple files interactively, squashing, reordering or amending commits in between.</p></div><div class='episode'><b>Customizing Git</b><p>Setup aliases for common commands and other personal options in Git - autocompletion, bash branch, colors and more.</p></div></div><div class="span-5"><h2>Advanced</h2><div class='episode'><b>Filter Branch</b><p>Modify large sections of your commit history at once, changing emails, names or files globally.</p></div><div class='episode'><b>Maintaining Git</b><p>Learn the fsck and gc commands to diagnose problems and keep your repository small.</p></div><div class='episode'><b>The Git Reflog</b><p>Browse the history of your local references even if they're not referenced anywhere else anymore.</p></div><div class='episode'><b>Data Recovery</b><p>Find lost commits or branches and restore them, or recover from partial database corruption.</p></div><div class='episode'><b>Git Hooks</b><p>Learn the client and server side pre and post action hooks and some useful example scripts to use with them.</p></div><div class='episode'><b>Revision Selection</b><p>Selecting individual commits or ranges of commits using helpful Git shorthands.</p></div><div class='episode'><b>Git Internals</b><p>Explore the internal workings of Git - the different object types and how to view the raw data via several useful plumbing commands.</p></div><div class='episode'><b>Git Submodules</b><p>Submodule usage and other tips for keeping subprojects in your Git repository.</p></div></div><div class="span-6 last"><h2>Special Interest</h2><div class='episode'><b>Git and Windows - General</b><p>Install and use Git on a Windows environment using the default mSysGit tools.</p></div><div class='episode'><b>Git and Windows - Extensions</b><p>Installing and using the Git Extensions shell extensions tools on Windows.</p></div><div class='episode'><b>Git and Subversion</b><p>Using the git-svn client with a Subversion server. Specifically for existing SVN users, how Git is a better Subversion client than Subversion.</p></div><div class='episode'><b>Migrating from Subversion</b><p>Ready to move your project from Subversion? A few ways to do the migration, from hosted services to really custom methods.</p></div><div class='episode'><b>Git and Textmate</b><p>Using Git and GitHub from Textmate using the TM Git bundle.</p></div><div class='episode'><b>Git and Capistrano</b><p>Deploying Git projects using the Capistrano deployment tool, including how to deploy from GitHub.</p></div></div>
<div id="footer" class="span-21">
<div class="info span-12">
View
2  p/diff.html
@@ -236,7 +236,7 @@ <h3 id='what_a_merge_would_introduce'>what a merge would introduce</h3>
<pre><code>$ git diff ...(branch)</code></pre>
-<p>Where (branch) is the name of the branch you&#8217;re considering merging.</p><br/><br/><hr/></div><div class="span-10"><a href="log.html">&laquo; previous</a></div><div style="text-align:right" class="span-11 last"><a href="undoing.html">next &raquo;</a></div><div class="span-21 last">&nbsp;</div><hr/>
+<p>Where (branch) is the name of the branch you&#8217;re considering merging.</p><br/><br/><hr/></div><div class="span-10"><a href="log.html">&laquo; previous</a></div><div style="text-align:right" class="span-11 last"><a href="rebasing.html">next &raquo;</a></div><div class="span-21 last">&nbsp;</div><hr/>
</div>
<div id="footer" class="span-21">
View
2  p/rebasing.html
@@ -128,7 +128,7 @@ <h2 id='do_not_rebase_commits_that_you_have_pushed_to_a_public_repository'>&#822
<p>When you rebase stuff, you are abandoning existing commits and creating new ones that are similar but still different. That means that if you push commits somewhere that others can pull them down and base work off of them, then you rewrite those commits and push them up again, you collaborators will have to re-merge their work again and things will get messy when you try to pull thier work back into yours.</p>
-<p>If you treat rebase as a way to clean up and work with commits <em>before</em> you push them, and only ever rebase commits that have never been available publicly, then you&#8217;ll be living the sweet life.</p><br/><br/><hr/></div><div class="span-10"><a href="undoing.html">&laquo; previous</a></div><div style="text-align:right" class="span-11 last"><a href="stashing.html">next &raquo;</a></div><div class="span-21 last">&nbsp;</div><hr/>
+<p>If you treat rebase as a way to clean up and work with commits <em>before</em> you push them, and only ever rebase commits that have never been available publicly, then you&#8217;ll be living the sweet life.</p><br/><br/><hr/></div><div class="span-10"><a href="diff.html">&laquo; previous</a></div><div style="text-align:right" class="span-11 last"><a href="stashing.html">next &raquo;</a></div><div class="span-21 last">&nbsp;</div><hr/>
</div>
<div id="footer" class="span-21">
View
2  p/stashing.html
@@ -42,7 +42,7 @@
</div>
<div class="content">
- <div class="span-21"><hr/><br/><br/><hr/></div><div class="span-10"><a href="rebasing.html">&laquo; previous</a></div><div class="span-21 last">&nbsp;</div><hr/>
+ <div class="span-21"><hr/><br/><br/><hr/></div><div class="span-10"><a href="rebasing.html">&laquo; previous</a></div><div style="text-align:right" class="span-11 last"><a href="undoing.html">next &raquo;</a></div><div class="span-21 last">&nbsp;</div><hr/>
</div>
<div id="footer" class="span-21">
View
124 p/undoing.html
@@ -42,13 +42,133 @@
</div>
<div class="content">
- <div class="span-21"><hr/><h3 id='unstaging_files'>unstaging files</h3>
+ <div class="span-21"><hr/><p>There are a number of situations in Git where you may want to undo or revert a change that you made. Perhaps you staged a file and then decided that you didn&#8217;t want it staged, or you edited a file and then wanted to &#8216;un-edit&#8217; it. This section will explore a couple of ways you can undo or revert actions in Git.</p>
+
+<h3 id='unstaging_files'>unstaging files</h3>
+
+<p>Here we&#8217;ve staged changes to both our REAME and simplegit.rb files, but then we decide that we want the changes to be two seperate commits. So, we need to unstage one, do a commit, then stage it again and do our second commit. Luckily, Git reminds you how to do this right in the &#8216;git status&#8217; command output.</p>
+
+<pre><code>$ git status
+# On branch nolimit
+# Changes to be committed:
+# (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)
+#
+# modified: README
+# modified: lib/simplegit.rb
+#</code></pre>
+
+<p>If you ever forget how to unstage a file, just run the &#8216;git status&#8217; command to remind yourself with the <em>(use &#8220;git reset HEAD (file)&#8230;&#8221; to unstage)</em> text. So lets use that to unstage the README file.</p>
+
+<pre><code>$ git reset HEAD README
+README: locally modified</code></pre>
+
+<p>Now if we run the &#8216;status&#8217; command again, we can see that the README file is no longer staged.</p>
+
+<pre><code>$ git status
+# On branch nolimit
+# Changes to be committed:
+# (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)
+#
+# modified: lib/simplegit.rb
+#
+# Changed but not updated:
+# (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)
+# (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)
+#
+# modified: README
+#</code></pre>
+
+<p>If you want an easier way of remembering this, you can add an &#8216;unstage&#8217; alias in your Git config file.</p>
+
+<pre><code>$ git config --global alias.unstage &#39;reset HEAD&#39;</code></pre>
+
+<p>Then you can just run:</p>
+
+<pre><code>$ git unstage README</code></pre>
+
+<p>A bit nicer, yes?</p>
<h3 id='unmodifying_files'>unmodifying files</h3>
+<p>Now, lets say that we want to completely throw away the changes we made to the README file altogether. <strong>Be careful - this is almost never a great idea and there is no way to get changes back if you do this!</strong> Things you commit are almost always recoverable, but if you throw them away before you commit, you&#8217;re out of luck if you ever want them back. However, if you DID want to do this, &#8216;git status&#8217; again gives you a nice tip.</p>
+
+<pre><code>$ git status
+# On branch nolimit
+# Changed but not updated:
+# (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)
+# (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)
+#
+# modified: README
+# modified: lib/simplegit.rb
+#</code></pre>
+
+<p>So, to &#8216;discard changes in working directory&#8217;, you simply run</p>
+
+<pre><code>$ git checkout -- README
+$ git status
+# On branch nolimit
+# Changed but not updated:
+# (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)
+# (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)
+#
+# modified: lib/simplegit.rb
+#</code></pre>
+
+<p>And the README changes are gone. If you instantly regret that choice, your only recourse is weeping upon your pillow.</p>
+
<h3 id='resetting_a_project'>resetting a project</h3>
-<h4 id='breaking_work_into_a_topic_branch'>breaking work into a topic branch</h4><br/><br/><hr/></div><div class="span-10"><a href="diff.html">&laquo; previous</a></div><div style="text-align:right" class="span-11 last"><a href="rebasing.html">next &raquo;</a></div><div class="span-21 last">&nbsp;</div><hr/>
+<p>Another powerful and easily destructive tool is the &#8216;reset &#8211;hard&#8217; command. This will forcefully replace your staging area and working directory with an older version and move your current branch there. So, lets say you did a couple of commits and then completely change your mind and want to just wipe them away.</p>
+
+<p>Let&#8217;s say your history log looked like this:</p>
+
+<pre><code>$ git log --pretty=oneline
+5ddae49fa3f36d892851cbb28549af98d36338fc added staged command
+92a4920c418f7545f995d0c9562f63d1b0f0b48f introduced shortlog and a new author
+a6b4c97498bd301d84096da251c98a07c7723e65 beginning write support
+0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function
+9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
+964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo</code></pre>
+
+<p>and you want to completely throw away the top two commits. All you have to do is reset your current branch to the sha of the commit you want to rewind to. In this case, the &#8216;beginning write support&#8217; or &#8216;a6b4c974&#8217;.</p>
+
+<p><img src='../images/undo/step1.png' alt='Reset 1' /></p>
+
+<pre><code>$ git reset --hard a6b4c974
+HEAD is now at a6b4c97 beginning write support</code></pre>
+
+<p><img src='../images/undo/step2.png' alt='Reset 2' /></p>
+
+<p>So, whatever branch we were on (in this case, &#8216;master&#8217;), is now pointing at our older commit, and commits we do from that point forward will move forward from there, leaving the ones we rewound past behind.</p>
+
+<p><img src='../images/undo/step3.png' alt='Reset 3' /></p>
+
+<h3 id='breaking_work_into_a_topic_branch'>breaking work into a topic branch</h3>
+
+<p>You can also use the &#8217;&#8211;hard&#8217; option for good. Let&#8217;s say you did a couple of commits on your &#8216;master&#8217; branch that after you&#8217;ve committed them you decide should really have been on a topic branch. How do we move those commits to a topic branch? Turns out it&#8217;s pretty easy, actually - you just create the branch where you are, then move the &#8216;master&#8217; pointer back to where you should have left it. Let&#8217;s do the same example, but this time leave our commits in a topic branch for later.</p>
+
+<p><img src='../images/undo/step1.png' alt='Reset 1' /></p>
+
+<p>First, we drop a &#8216;bookmark&#8217; where we are. This is generally a useful idea - if you&#8217;re going to try something you are not sure is going to work, just create a branch where you are, so you can always get back to there.</p>
+
+<pre><code>$ git branch test</code></pre>
+
+<p><img src='../images/undo/topic2.png' alt='Reset Topic 2' /></p>
+
+<p>Now we have a branch at the point we were and can move around the &#8216;master&#8217; branch with the &#8216;reset&#8217; command. Let&#8217;s do our reset to the older commit.</p>
+
+<pre><code>$ git reset --hard a6b4c974
+HEAD is now at a6b4c97 beginning write support</code></pre>
+
+<p><img src='../images/undo/topic3.png' alt='Reset Topic 3' /></p>
+
+<p>Now we can start working again and our master branch will move forward as if we had branched seperately from our &#8216;test&#8217; branch originally.</p>
+
+<pre><code>$ git commit</code></pre>
+
+<p><img src='../images/undo/topic4.png' alt='Reset Topic 4' /></p>
+
+<p>And now our commits are tucked away in a branch that we can come back to later if we want to.</p><br/><br/><hr/></div><div class="span-10"><a href="stashing.html">&laquo; previous</a></div><div class="span-21 last">&nbsp;</div><hr/>
</div>
<div id="footer" class="span-21">
View
156 pages/undoing.markdown
@@ -1,12 +1,164 @@
-
+There are a number of situations in Git where you may want to undo or revert
+a change that you made. Perhaps you staged a file and then decided that you
+didn't want it staged, or you edited a file and then wanted to 'un-edit' it.
+This section will explore a couple of ways you can undo or revert actions in
+Git.
+
### unstaging files ###
+Here we've staged changes to both our REAME and simplegit.rb files, but then
+we decide that we want the changes to be two seperate commits. So, we need to
+unstage one, do a commit, then stage it again and do our second commit. Luckily,
+Git reminds you how to do this right in the 'git status' command output.
+
+ $ git status
+ # On branch nolimit
+ # Changes to be committed:
+ # (use "git reset HEAD <file>..." to unstage)
+ #
+ # modified: README
+ # modified: lib/simplegit.rb
+ #
+
+If you ever forget how to unstage a file, just run the 'git status' command
+to remind yourself with the _(use "git reset HEAD (file)..." to unstage)_
+text. So lets use that to unstage the README file.
+
+ $ git reset HEAD README
+ README: locally modified
+
+Now if we run the 'status' command again, we can see that the README file is
+no longer staged.
+ $ git status
+ # On branch nolimit
+ # Changes to be committed:
+ # (use "git reset HEAD <file>..." to unstage)
+ #
+ # modified: lib/simplegit.rb
+ #
+ # Changed but not updated:
+ # (use "git add <file>..." to update what will be committed)
+ # (use "git checkout -- <file>..." to discard changes in working directory)
+ #
+ # modified: README
+ #
+
+If you want an easier way of remembering this, you can add an 'unstage' alias
+in your Git config file.
+
+ $ git config --global alias.unstage 'reset HEAD'
+
+Then you can just run:
+
+ $ git unstage README
+
+A bit nicer, yes?
+
### unmodifying files ###
+Now, lets say that we want to completely throw away the changes we made to
+the README file altogether. **Be careful - this is almost never a great idea
+and there is no way to get changes back if you do this!** Things you commit
+are almost always recoverable, but if you throw them away before you commit,
+you're out of luck if you ever want them back. However, if you DID want to
+do this, 'git status' again gives you a nice tip.
+
+ $ git status
+ # On branch nolimit
+ # Changed but not updated:
+ # (use "git add <file>..." to update what will be committed)
+ # (use "git checkout -- <file>..." to discard changes in working directory)
+ #
+ # modified: README
+ # modified: lib/simplegit.rb
+ #
+
+So, to 'discard changes in working directory', you simply run
+
+ $ git checkout -- README
+ $ git status
+ # On branch nolimit
+ # Changed but not updated:
+ # (use "git add <file>..." to update what will be committed)
+ # (use "git checkout -- <file>..." to discard changes in working directory)
+ #
+ # modified: lib/simplegit.rb
+ #
+
+And the README changes are gone. If you instantly regret that choice, your
+only recourse is weeping upon your pillow.
### resetting a project ###
+Another powerful and easily destructive tool is the 'reset --hard' command.
+This will forcefully replace your staging area and working directory with
+an older version and move your current branch there. So, lets say you did
+a couple of commits and then completely change your mind and want to just
+wipe them away.
+
+Let's say your history log looked like this:
+
+ $ git log --pretty=oneline
+ 5ddae49fa3f36d892851cbb28549af98d36338fc added staged command
+ 92a4920c418f7545f995d0c9562f63d1b0f0b48f introduced shortlog and a new author
+ a6b4c97498bd301d84096da251c98a07c7723e65 beginning write support
+ 0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function
+ 9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
+ 964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo
+
+and you want to completely throw away the top two commits. All you have to
+do is reset your current branch to the sha of the commit you want to rewind to.
+In this case, the 'beginning write support' or 'a6b4c974'.
+
+![Reset 1](../images/undo/step1.png)
+
+ $ git reset --hard a6b4c974
+ HEAD is now at a6b4c97 beginning write support
+
+![Reset 2](../images/undo/step2.png)
+
+So, whatever branch we were on (in this case, 'master'), is now pointing at
+our older commit, and commits we do from that point forward will move forward
+from there, leaving the ones we rewound past behind.
+
+![Reset 3](../images/undo/step3.png)
+
+
+### breaking work into a topic branch ###
+
+You can also use the '--hard' option for good. Let's say you did a couple
+of commits on your 'master' branch that after you've committed them you decide
+should really have been on a topic branch. How do we move those commits to
+a topic branch? Turns out it's pretty easy, actually - you just create the
+branch where you are, then move the 'master' pointer back to where you should
+have left it. Let's do the same example, but this time leave our commits in
+a topic branch for later.
+
+![Reset 1](../images/undo/step1.png)
+
+First, we drop a 'bookmark' where we are. This is generally a useful idea -
+if you're going to try something you are not sure is going to work, just
+create a branch where you are, so you can always get back to there.
+
+ $ git branch test
+
+![Reset Topic 2](../images/undo/topic2.png)
+
+Now we have a branch at the point we were and can move around the 'master'
+branch with the 'reset' command. Let's do our reset to the older commit.
+
+ $ git reset --hard a6b4c974
+ HEAD is now at a6b4c97 beginning write support
+
+![Reset Topic 3](../images/undo/topic3.png)
+
+Now we can start working again and our master branch will move forward as
+if we had branched seperately from our 'test' branch originally.
+
+ $ git commit
-#### breaking work into a topic branch ####
+![Reset Topic 4](../images/undo/topic4.png)
+And now our commits are tucked away in a branch that we can come back to later
+if we want to.

0 comments on commit b6bce8f

Please sign in to comment.
Something went wrong with that request. Please try again.