What does git reset –hard do to your commit history and changes?
The git reset command moves the current branch, and HEAD with it, to another commit. --soft stops there. --mixed, the default, also resets the index (the staging area), and --hard also rewrites the files in your working directory to match that commit.
That makes --hard the only reset mode that destroys data, as Pro Git puts it. A commit it takes off the branch can still be found in the reflog, Git’s record of where HEAD has been. Changes it overwrites that you never staged or committed are lost for good.
git reset --hard HEAD keeps the branch in place and discards uncommitted changes to tracked files. git reset --hard HEAD~1 also drops the last commit (HEAD~1 is the commit just before HEAD).
Compare git reset soft, mixed and hard
Pro Git describes reset as three steps in a fixed order. Each mode stops after a different one:
- Move the branch HEAD points to onto the target commit.
git reset --softstops here. - Make the index look like the new HEAD.
git reset --mixed, the default mode, stops here. - Make the working directory look like the index. Only
git reset --hardgoes this far.
Here is the result when the last commit added scripts/seed.ts and you reset to HEAD~1 with each mode:
- After
--soft, the changes are still staged:git status -sshowsA scripts/seed.ts. - After
--mixed, the file stays on disk but leaves the index. Git lists its folder as untracked,?? scripts/, until you usegit addagain. - After
--hard, the file is gone andgit status -sprints nothing.
git reset with no argument is git reset --mixed HEAD. The branch does not move, the index matches HEAD again, and your edits stay in the working tree: it unstages everything.
Use git reset –soft HEAD1 or git reset –hard HEAD1 to undo a commit
Soft or hard depends on one question: do you want to keep the changes of the last commit? The examples use a throwaway repository, orbit-api, with outputs from Git 2.23; your hashes will differ. Read the commit history first, so you know which commit HEAD~1 is:
git log --oneline -3
0faa9aa Add a seed script
735f338 Hide archived projects from search results
cf8f374 Add project search
To remove 0faa9aa and keep its changes staged for a new commit, use git reset --soft HEAD~1. To drop the commit and its changes, use --hard:
git reset --hard HEAD~1
HEAD is now at 735f338 Hide archived projects from search results
HEAD~3 removes the last three commits, and a commit hash resets the branch to that specific commit.
A hard reset does not ask for confirmation. Before using git reset --hard, run git status, then commit or stash the local changes you want to keep.
If you only need a better message or a forgotten file, amend the last commit instead.
Recover a commit after git reset –hard with git reflog
If you ran the hard reset by mistake, git reflog lists the positions HEAD went through, the reset included:
git reflog -3
735f338 HEAD@{0}: reset: moving to HEAD~1
0faa9aa HEAD@{1}: commit: Add a seed script
735f338 HEAD@{2}: commit: Hide archived projects from search results
HEAD@{1} is where the branch stood before the reset. Reset back to it, or run git checkout -b rescue 0faa9aa to look at the commit on a new branch first:
git reset --hard HEAD@{1}
HEAD is now at 0faa9aa Add a seed script
Only commits come back this way: uncommitted changes are not in the reflog, and --hard overwrote them.
Reflog entries also expire, according to the git reflog documentation. By default, Git keeps them 90 days (gc.reflogExpire), but only 30 days once they are no longer reachable from the branch tip (gc.reflogExpireUnreachable), as with a commit you reset away: do not wait a month.
In GitMini, right-click a commit in the graph and choose Reset main to here…: the dialog offers Soft, Mixed (the default), Keep and Hard. Soft, mixed and keep resets end with an Undo toast. Hard warns that it cannot be undone, and what it overwrites skips the app’s Discarded tab. The reflog panel lists where HEAD has been, with Create a branch here… on each entry.
Choose git revert instead of git reset on a shared branch
A reset takes commits off your branch. If you already pushed them, the remote still has them, and so does anyone who pulled: your local history no longer matches theirs. git revert records a new commit that reverses the effect of an earlier one, so nothing leaves the history.
The rule is short. Commits nobody else has: reset. Commits already pushed: revert.
Sources
- Git documentation: git-reset, consulted on November 8, 2026.
- Pro Git: Reset Demystified, consulted on November 8, 2026.
- Git documentation: git-reflog, consulted on November 8, 2026.
- Git documentation: git-revert, consulted on November 8, 2026.
- GitMini product README and app (version 0.3.1), consulted on November 10, 2026.