From 1bb6a708ec9f86e54712dde965c2eaf34c485d68 Mon Sep 17 00:00:00 2001 From: Richard Littauer Date: Fri, 3 Jul 2015 16:22:51 -0400 Subject: [PATCH] How to undo a hard reset --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index eb550de..3499a3a 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ For clarity's sake all examples in this document use a customized bash prompt in - [I pulled from/into the wrong branch](#i-pulled-frominto-the-wrong-branch) - [I want to discard local commits so my branch is the same as one on the server](#i-want-to-discard-local-commits-so-my-branch-is-the-same-as-one-on-the-server) - [I want to discard my local, uncommitted changes](#i-want-to-discard-my-local-uncommitted-changes) + - [I accidentally did a hard reset, and I want my changes back](#i-accidentally-did-a-hard-reset-and-i-want-my-changes-back) - [I want to move my unstaged edits to a new branch](#i-want-to-move-my-unstaged-edits-to-a-new-branch) - [I want to move my unstaged edits to a different, existing branch](#i-want-to-move-my-unstaged-edits-to-a-different-existing-branch) - [What did I just do?](#what-did-i-just-do) @@ -474,6 +475,23 @@ If you want to only reset to some commit between origin and your local, you can (master)$ git checkout -f ``` + +## I accidentally did a hard reset, and I want my changes back + +If you accidentally do `git reset --hard`, you can normally still get your commit back, as git keeps a log of everything for a few days. + +```sh +$(master) git reflog +``` + +You'll see a list of your past commits, and a commit for the reset. Choose the SHA of the commit you want to return to, and reset again: + +```sh +$(master) git reset --hard SHA1234 +``` + +And you should be good to go. + ## I want to move my unstaged edits to a new branch