How to Recover Commits Deleted with git reset Using git reflog
You can recover a commit deleted with git reset --hard by finding its hash in git reflog. A commit disappears from git log after a reset, but it is not deleted right away. You can find it in the record of where HEAD has pointed (the reflog). I checked how to undo an accidental reset by comparing the output before and after the operation. This article also covers recovering commits when you made new commits after the reset, and finding files that were only staged with git add.
The test environment was Ubuntu 24.04 with Git 2.43.0. I set the author name and email to example values (Neko <neko@example.com>), and I set the commit dates with environment variables so the output would be the same each time. I did not test pushing to a remote, Windows or macOS, or other Git versions.
Deleting Two Commits with reset –hard
In a repository where I committed "Add profile" and "Add photo list" after the "Initial commit," I ran git reset --hard HEAD~2 to go back two commits.
$ git log --oneline
aadb0ca 写真の一覧を追加
e3532fc プロフィールを追加
5f65efe 最初のコミット
$ ls
README.md
photos.html
profile.html
$ git reset --hard HEAD~2
HEAD is now at 5f65efe 最初のコミット
$ git log --oneline
5f65efe 最初のコミット
$ ls
README.md
The two commits disappeared from git log, and profile.html and photos.html were removed from the folder.
Finding the Original Hash with git reflog
git reflog lists the commits that HEAD has pointed to, newest first (git reflog reference).
$ git reflog
5f65efe HEAD@{0}: reset: moving to HEAD~2
aadb0ca HEAD@{1}: commit: 写真の一覧を追加
e3532fc HEAD@{2}: commit: プロフィールを追加
5f65efe HEAD@{3}: commit (initial): 最初のコミット
HEAD@{0} at the top is the reset I just ran. The line below it, HEAD@{1}, is the commit HEAD pointed to before the reset: "Add photo list" (aadb0ca).

To search by time, add --date=iso. Then the dates appear in place of HEAD@{1}.
$ git reflog --date=iso
5f65efe HEAD@{2026-11-11 10:30:00 +0900}: reset: moving to HEAD~2
aadb0ca HEAD@{2026-11-11 10:20:00 +0900}: commit: 写真の一覧を追加
e3532fc HEAD@{2026-11-11 10:10:00 +0900}: commit: プロフィールを追加
5f65efe HEAD@{2026-11-11 10:00:00 +0900}: commit (initial): 最初のコミット
Before restoring the commit, it is a good idea to check its contents with git show. You can pass HEAD@{1} to a command in place of a hash (revision syntax reference).
$ git show --stat --oneline HEAD@{1}
aadb0ca 写真の一覧を追加
photos.html | 1 +
1 file changed, 1 insertion(+)
Restoring with reset –hard
Run git reset --hard again, specifying the commit you found. The tip of the branch moves back to that commit.
$ git reset --hard HEAD@{1}
HEAD is now at aadb0ca 写真の一覧を追加
$ git log --oneline
aadb0ca 写真の一覧を追加
e3532fc プロフィールを追加
5f65efe 最初のコミット
$ ls
README.md
photos.html
profile.html
Both commits are back, along with profile.html and photos.html.
The reflog also has one more line now, for the restore operation.
$ git reflog
aadb0ca HEAD@{0}: reset: moving to HEAD@{1}
5f65efe HEAD@{1}: reset: moving to HEAD~2
aadb0ca HEAD@{2}: commit: 写真の一覧を追加
e3532fc HEAD@{3}: commit: プロフィールを追加
5f65efe HEAD@{4}: commit (initial): 最初のコミット
"Add photo list," which was HEAD@{1} before, is now HEAD@{2}. HEAD@{n} means "where HEAD pointed n operations ago," so the numbers shift with every operation. If you run other commands after looking at the reflog, specify the commit by hash, such as aadb0ca, to avoid picking the wrong one.
When You Made New Commits After the Reset
I also tested the case where I did not notice the reset and committed "Add contact page" on top of it.
$ git reset --hard HEAD~2
HEAD is now at 5f65efe 最初のコミット
$ echo '<h1>お問い合わせ</h1>' > contact.html
$ git add contact.html
$ git commit -q -m 'お問い合わせを追加'
$ git log --oneline
af770f4 お問い合わせを追加
5f65efe 最初のコミット
$ git reflog
af770f4 HEAD@{0}: commit: お問い合わせを追加
5f65efe HEAD@{1}: reset: moving to HEAD~2
aadb0ca HEAD@{2}: commit: 写真の一覧を追加
e3532fc HEAD@{3}: commit: プロフィールを追加
5f65efe HEAD@{4}: commit (initial): 最初のコミット
The deleted commit is aadb0ca, at HEAD@{2}. However, the history up to aadb0ca does not include "Add contact page." So instead of resetting main to aadb0ca, I re-apply the deleted commits on top of the current main.
First, create a branch named rescue at aadb0ca. You can also run git log --oneline rescue to confirm that "Add contact page" is not in the history up to aadb0ca.
$ git branch rescue HEAD@{2}
$ git log --oneline rescue
aadb0ca 写真の一覧を追加
e3532fc プロフィールを追加
5f65efe 最初のコミット
Next, use git cherry-pick main..rescue to re-apply the commits in rescue that are not in main, on top of the current main. cherry-pick creates a new commit for each of the specified commits, with the same changes (git cherry-pick reference).
$ git cherry-pick main..rescue
[main 7916e5d] プロフィールを追加
Date: Wed Nov 11 10:10:00 2026 +0900
1 file changed, 1 insertion(+)
create mode 100644 profile.html
[main c8e515f] 写真の一覧を追加
Date: Wed Nov 11 10:20:00 2026 +0900
1 file changed, 1 insertion(+)
create mode 100644 photos.html
$ git log --oneline
c8e515f 写真の一覧を追加
7916e5d プロフィールを追加
af770f4 お問い合わせを追加
5f65efe 最初のコミット
$ ls
README.md
contact.html
photos.html
profile.html
The two deleted commits are back, and "Add contact page" is still there. The re-applied commits are newly created, so their hashes are now 7916e5d and c8e515f.
I could not delete the rescue branch with git branch -d. The commits e3532fc and aadb0ca in rescue are not included in main, because main has the re-applied copies instead. After confirming with git log that the commits were restored, I deleted the branch with -D (git branch reference).
$ git branch -d rescue
error: the branch 'rescue' is not fully merged.
If you are sure you want to delete it, run 'git branch -D rescue'
$ git branch -D rescue
Deleted branch rescue (was aadb0ca).
Finding Files That Were Only Staged with git fsck
The HEAD reflog only records the commits that HEAD has pointed to. A file that you staged with git add but did not commit does not appear in the reflog after a reset.
$ echo '<h1>お知らせ</h1>' > news.html
$ git add news.html
$ git status --short
A news.html
$ git reset --hard HEAD
HEAD is now at aadb0ca 写真の一覧を追加
$ ls
README.md
photos.html
profile.html
$ git reflog -1
aadb0ca HEAD@{0}: reset: moving to HEAD
However, the contents of the staged file were still in Git's database after the reset. Data that nothing refers to is reported by git fsck as "dangling." With --lost-found, the contents are written to .git/lost-found/other/ (git fsck reference).
$ git fsck --lost-found
dangling blob d2c0e058cf47cee60fccf964d12ac67b8d0513b7
$ ls .git/lost-found/other
d2c0e058cf47cee60fccf964d12ac67b8d0513b7
$ cat .git/lost-found/other/*
<h1>お知らせ</h1>
I found the contents of news.html. The name of the written file is a hash, so the original file name is not shown. Look at the contents to determine which file it was.
When Recovery Is Not Possible
Changes that were not staged with git add were not recovered. After a reset, git fsck --lost-found showed nothing for them.
$ echo '更新中のメモ' >> README.md
$ git status --short
M README.md
$ git reset --hard HEAD
HEAD is now at aadb0ca 写真の一覧を追加
$ cat README.md
# Cat Notebook
$ git fsck --lost-found
Reflog entries are not kept forever. According to the configuration notes in the git gc reference, reflog entries older than 90 days by default are removed, and entries for commits that cannot be reached from the current branch tip and are older than 30 days by default are also removed, when git reflog expire runs. Normally this runs as part of git gc. git gc is the command that cleans up old reflog entries and deletes data that nothing refers to.
To check this without waiting for the expiry period, I expired the reflog entries right after a reset and then used git gc to delete the unreferenced data.
$ git reset --hard HEAD~2
HEAD is now at 5f65efe 最初のコミット
$ git reflog expire --expire=now --expire-unreachable=now --all
$ git reflog
$ git gc --prune=now -q
$ git show --stat --oneline aadb0ca
fatal: ambiguous argument 'aadb0ca': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
The reflog is empty, and aadb0ca can no longer be found.
If you want to restore a commit deleted with git reset --hard, find it in the reflog before running git gc or git reflog expire. Running git gc can also permanently delete commits that have dropped out of the reflog, and the contents of files that were only staged with git add.



