<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>brool &#187; reset</title>
	<atom:link href="http://www.brool.com/index.php/tag/reset/feed" rel="self" type="application/rss+xml" />
	<link>http://www.brool.com</link>
	<description>brool \brool\ (n.) : a low roar; a deep murmur or humming</description>
	<lastBuildDate>Fri, 20 Jan 2012 07:58:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Recovering From A &#8211;hard Reset In Git</title>
		<link>http://www.brool.com/index.php/recovering-from-a-hard-reset-in-git</link>
		<comments>http://www.brool.com/index.php/recovering-from-a-hard-reset-in-git#comments</comments>
		<pubDate>Sun, 19 Apr 2009 06:37:09 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[hard]]></category>
		<category><![CDATA[recovering]]></category>
		<category><![CDATA[reset]]></category>

		<guid isPermaLink="false">http://www.brool.com/?p=303</guid>
		<description><![CDATA[I was switching between git repositories the other day, and managed to do a &#8220;git reset &#8211;hard HEAD^&#8221; in the wrong repository. Which wasn&#8217;t bad, since I had most of the files already open in Emacs&#8230; but then Emacs calmly told me that it was re-reading the files from disk. But, git had everything still [...]]]></description>
			<content:encoded><![CDATA[I was switching between git repositories the other day, and managed to do a &#8220;git reset &#8211;hard HEAD^&#8221; in the wrong repository.  Which wasn&#8217;t bad, since I had most of the files already open in Emacs&#8230; but then Emacs calmly told me that it was re-reading the files from disk.

But, git had everything still around &#8212; it turns out to be pretty easy to get it back.  The magic command turned out to be git reflog.


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1">$ <span class="kw2">git reflog</span>
aba2b93... HEAD<span class="sy0">@</span><span class="br0">&#123;</span><span class="nu0">0</span><span class="br0">&#125;</span>: reset <span class="re5">--hard</span> HEAD^
28a0c01... HEAD<span class="sy0">@</span><span class="br0">&#123;</span><span class="nu0">1</span><span class="br0">&#125;</span>: commit: <span class="kw2">more</span> work on pre-receive
1c4a3af... HEAD<span class="sy0">@</span><span class="br0">&#123;</span><span class="nu0">2</span><span class="br0">&#125;</span>: merge tmp: Fast forward
84d69cb... HEAD<span class="sy0">@</span><span class="br0">&#123;</span><span class="nu0">3</span><span class="br0">&#125;</span>: checkout: moving to commit_hooks
1c4a3af... HEAD<span class="sy0">@</span><span class="br0">&#123;</span><span class="nu0">4</span><span class="br0">&#125;</span>: commit: commit hooks
a489ebd... HEAD<span class="sy0">@</span><span class="br0">&#123;</span><span class="nu0">5</span><span class="br0">&#125;</span>: checkout: moving to tmp
a489ebd... HEAD<span class="sy0">@</span><span class="br0">&#123;</span><span class="nu0">6</span><span class="br0">&#125;</span>: checkout: moving to a489ebd</pre></div></div></div></div></div></div></div>




So I had lost everything in HEAD@{1}, but you can get it back by just checking out that particular commit.


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1">$ <span class="kw2">git checkout</span> HEAD<span class="sy0">@</span><span class="br0">&#123;</span><span class="nu0">1</span><span class="br0">&#125;</span>
Note: moving to <span class="st0">&quot;28a0c01&quot;</span> <span class="kw2">which</span> isn<span class="st_h">'t a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
  git checkout -b &lt;new_branch_name&gt;
HEAD is now at 28a0c01... commit: more work on pre-receive
&nbsp;
$ git checkout -b tmp
... do whatever you need to do to get tmp to the right state ...
&nbsp;
$ git checkout master
$ git merge tmp</span></pre></div></div></div></div></div></div></div>




Note that if I didn&#8217;t need to fiddle around with stuff, but just had wanted everything in the commit, I could just have merged the entire commit:


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="co4">$ </span><span class="kw2">git merge</span> HEAD<span class="sy0">@</span><span class="br0">&#123;</span><span class="nu0">1</span><span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>




&#8230; and that would have brought everything back to the state I needed.]]></content:encoded>
			<wfw:commentRss>http://www.brool.com/index.php/recovering-from-a-hard-reset-in-git/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

