Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I accidentally ran git reset HEAD~12 when I meant to run get reset HEAD~1. How can I recover the commits I just reset?

About eight of the commits were pushed to a remote before the reset. The others were only present on my machine.

Just in case it's useful, here's the output of git fsck --lost-found

dangling tree a58117938f93b1ebcdf5d10f10e2aff30b76dc31
dangling commit 15f2b2c8843a12c9fb6f39a4f4dc08351e7f4d73
dangling commit 2c8261414491eb9a9f63e2dc4231f88455945926
dangling tree 35e25b9cbeda0176625f8e34bf54ded457875ffa
dangling commit bac28f261e9cd8652c5e648ada4f0dafd11234c7
dangling tree 18735078b8bc64793d21be69bb1132d1e65673b4
dangling commit 585324a540ee921c228dcb574e1731c52add0e8e
dangling commit 94b379ab9ce29ecf41dddfb919262e148f916eca
dangling commit 14d51a03f2ea8e90497df6d59d6f5cb9502b9fa2
dangling tree 14573e776026c2baf5a87989a58d4e30c94b034e
dangling commit 15d711245b3ae84cd164f5fde15afba8410754f1
dangling tree 2c170fe363e559f70ea3dfe60b44cf7b20099a48
dangling tree 33076973ad5a9b75e280df95ea60895838337e9c
dangling commit 4df7dff300723f021257e5e08d79f5c3e13e196d
dangling tree f3c7efc967816b4a34c956615527cc7c8313e69c
dangling commit f307ed0bf520c458d41e670cd4a443e207ccff59
dangling commit 9a08d648a2c8a8c6bc0e40aa667a5dde7496bd54
dangling commit d4888fd593655d5df54ce2a821ce9ebf47911af3
dangling commit 1609b1303b5c026ee5ebe0df725bc8b6a43fb077
dangling commit b4d903f6302c85847a32e0cb35e380a6cafa789d
dangling tree ca495c16e084820401de0a3e8512635e1517580e
dangling commit 56dafd9401085a32b6480a6d4a42fd73089937ec
dangling commit 8a7a90f08702ad91665f1805cec21ccd221cbd9c
dangling commit 989a3145b5cadb8fca249f08209d751cfc2f6b2e
dangling commit fa6a6765e6edca806efd964546eb8664c82e3dbc
dangling commit 17fb737b2f7e9f0a832e779032592eaff27232b8
dangling tree 241b976dc46ed6e8722c80d87bd839fd6c7e30cd
dangling commit 37eca2e44546c42584348cdbd3f1b88e6df8b45a
dangling commit 9eace3ee8c4cb9b7dd47963dc208232fb392e7ab
dangling commit 603ee383776b11081ce4b66ece113473cd1725bd
dangling commit b5ce5547aa9151a2ad4eee017d38abacf078f172
dangling commit feeeacf0e86214302cda079d50ca78dd5aec64dd
dangling commit 030fc2e3ba6a54946e2e09ae364242c1e39dbc75
dangling commit f23f6d5e9fb3bc4b5a80c91d2628eb92efec5604
share|improve this question
does git reflog still show your previous HEAD? if yes, just git reset it back to that. – mihi May 1 '13 at 17:10
It does. I have reset to the previous HEAD. You should post an answer. – Evan Teitelman May 1 '13 at 17:14
jokester was faster :) – mihi May 1 '13 at 17:16
up vote 10 down vote accepted

git reflog <BRANCH> (or git reflog show <BRANCH>) shows changes recently made to that branch, including commit/rebase.

If you found the was-HEAD^1 commit, you can git reset to the position again.

share|improve this answer
Most likely it'll be HEAD@{1}. – grawity May 1 '13 at 17:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .