<?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; hard</title>
	<atom:link href="http://www.brool.com/index.php/tag/hard/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>Sat, 26 Jun 2010 21:05:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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[<p>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.</p>
<p>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.</p>
<div class="codesnip-container" >$ git reflog<br />
aba2b93&#8230; HEAD@{0}: reset &#8211;hard HEAD^<br />
28a0c01&#8230; HEAD@{1}: commit: more work on pre-receive<br />
1c4a3af&#8230; HEAD@{2}: merge tmp: Fast forward<br />
84d69cb&#8230; HEAD@{3}: checkout: moving to commit_hooks<br />
1c4a3af&#8230; HEAD@{4}: commit: commit hooks<br />
a489ebd&#8230; HEAD@{5}: checkout: moving to tmp<br />
a489ebd&#8230; HEAD@{6}: checkout: moving to a489ebd</div>
<p>So I had lost everything in HEAD@{1}, but you can get it back by just checking out that particular commit.</p>
<div class="codesnip-container" >$ git checkout HEAD@{1}<br />
Note: moving to &#8220;28a0c01&#8243; which isn&#8217;t a local branch<br />
If you want to create a new branch from this checkout, you may do so<br />
(now or later) by using -b with the checkout command again. Example:<br />
  git checkout -b <new_branch_name><br />
HEAD is now at 28a0c01&#8230; commit: more work on pre-receive</p>
<p>$ git checkout -b tmp<br />
&#8230; do whatever you need to do to get tmp to the right state &#8230;</p>
<p>$ git checkout master<br />
$ git merge tmp</p></div>
<p>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:</p>
<div class="codesnip-container" >$ git merge HEAD@{1}</div>
<p>&#8230; and that would have brought everything back to the state I needed.</p>
]]></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>
