git-reset
Undo commits and changes
TLDR
Unstage everything
Unstage specific file(s)
Interactively unstage portions of a file
Undo the last commit, keeping its changes (and any further uncommitted changes) in the filesystem
Undo the last two commits, adding their changes to the index, i.e. staged for commit
Discard any uncommitted changes, staged or not (for only unstaged changes, use git checkout)
Reset the repository to a given commit, discarding committed, staged and uncommitted changes since then
SYNOPSIS
git reset [
PARAMETERS
--soft
Resets HEAD to the specified commit, leaving the staging area and working directory untouched.
--mixed
Resets HEAD and the staging area, but not the working directory. (Default)
--hard
Resets HEAD, the staging area, and the working directory.
Specifies the commit to reset to. Can be a commit hash, tag, branch, or relative reference (e.g., HEAD^, HEAD~2).
--merge
Resets HEAD and index like --mixed, but also refreshes the files in the working tree that are different between
--keep
Resets HEAD but keeps local changes.
-q, --quiet
Be quiet, only report errors.
--recurse-submodules
Control recursive updating of submodules.
-N, --intent-to-add
Stages the pathspecs.
Limits the reset to the specified files or directories.
DESCRIPTION
The git reset command is a powerful tool for undoing changes in your working directory and staging area. It allows you to move the current HEAD (the pointer to the current branch's last commit) to a specific commit, effectively rewriting history. There are three main reset modes: --soft, --mixed (default), and --hard.
--soft moves the HEAD to the specified commit, but leaves the staging area and working directory untouched. Your changes are preserved, but they are now staged. This is useful if you want to undo a commit but keep the changes.
--mixed (the default mode) moves the HEAD to the specified commit and resets the staging area to match. However, it leaves the working directory untouched. This is useful if you want to unstage changes but keep them in your working directory.
--hard moves the HEAD to the specified commit, resets the staging area, and resets the working directory. This is the most destructive mode and should be used with caution, as it will discard any changes in the staging area and working directory that are not in the target commit.
CAVEATS
Using --hard can result in data loss if you have uncommitted changes. Always double-check before using it. Resetting a public branch that others are working on can cause problems; avoid this if possible. Use git revert to undo changes on public branches.
DETACHED HEAD
Be aware that resetting in a detached HEAD state will move the detached HEAD pointer, and any commits only reachable from that HEAD may be lost if not referenced elsewhere. A branch reset is typically safer.
PATHSPEC LIMITATIONS
When using pathspecs, git reset only affects the listed files or directories. This can be useful for selectively unstaging or discarding changes.
HISTORY
The git reset command has been a core part of Git since its early development. It evolved from a simpler tool for just moving the HEAD pointer to a more sophisticated mechanism for managing the staging area and working directory. Over time, the different modes (--soft, --mixed, --hard) were added to provide more fine-grained control over the reset process.
SEE ALSO
git revert(1), git checkout(1), git commit(1)