Git - git-reset Documentation
English ▾ English Español Français Português (Brasil) Русский Svenska українська мова 简体中文 Topics ▾ Setup and Config git config help bugreport Credential helpers Getting and Creating Projects init clone Basic Snapshotting add status diff commit notes restore reset rm mv Branching and Merging branch checkout switch merge mergetool log stash tag worktree Sharing and Updating Projects fetch pull push remote submodule Inspection and Comparison show log diff difftool range-diff shortlog describe Patching apply cherry-pick diff rebase revert Debugging bisect blame grep Email am apply imap-send format-patch send-email request-pull External Systems svn fast-import Server Admin daemon update-server-info Guides gitattributes Command-line interface conventions Everyday Git Frequently Asked Questions (FAQ) Glossary Hooks gitignore gitmodules Revisions Submodules Tutorial Workflows All guides...
Administration clean gc fsck reflog filter-branch instaweb archive bundle Plumbing Commands cat-file check-ignore checkout-index commit-tree count-objects diff-index for-each-ref hash-object ls-files ls-tree merge-base read-tree rev-list rev-parse show-ref symbolic-ref update-index update-ref verify-pack write-tree Latest version ▾ git-reset last updated in 2.54.0 2.54.1 → 2.56.1 no changes 2.54.0 2026-04-20 2.53.1 no changes 2.53.0 2026-02-02 2.52.1 no changes 2.52.0 2025-11-17 2.51.1 → 2.51.3 no changes 2.51.0 2025-08-18 2.50.1 → 2.50.2 no changes 2.50.0 2025-06-16 2.39.4 → 2.49.1 no changes 2.39.3 2023-04-17 2.36.1 → 2.39.2 no changes 2.36.0 2022-04-18 2.34.1 → 2.35.8 no changes 2.34.0 2021-11-15 2.27.1 → 2.33.8 no changes 2.27.0 2020-06-01 2.25.1 → 2.26.3 no changes 2.25.0 2020-01-13 2.23.1 → 2.24.4 no changes 2.23.0 2019-08-16 2.22.1 → 2.22.5 no changes 2.22.0 2019-06-07 2.21.1 → 2.21.4 no changes 2.21.0 2019-02-24 2.20.1 → 2.20.5 no changes 2.20.0 2018-12-09 2.15.4 → 2.19.6 no changes 2.14.6 2019-12-06 2.13.7 2018-05-22 2.12.5 2017-09-22 2.1.4 → 2.11.4 no changes 2.0.5 2014-12-17 NAME git-reset - Set HEAD or the index to a known state SYNOPSIS git reset [ --soft | --mixed [ -N ] | --hard | --merge | --keep ] [ -q ] [ <commit> ] git reset [ -q ] [ <tree-ish> ] [ -- ] <pathspec> … git reset [ -q ] [ --pathspec-from-file= <file> [ --pathspec-file-nul ]] [ <tree-ish> ] git reset ( --patch | -p ) [ <tree-ish> ] [ -- ] [ <pathspec> …] DESCRIPTION git reset does either of the following: git reset [ <mode> ] <commit> changes which commit HEAD points to.
This makes it possible to undo various Git operations, for example commit, merge, rebase, and pull. When you specify files or directories or pass --patch , git reset updates the staged version of the specified files. git reset [ <mode> ] [ <commit> ] Set the current branch head ( HEAD ) to point at <commit> . Depending on <mode> , also update the working directory and/or index to match the contents of <commit> . <commit> defaults to HEAD .
Before the operation, ORIG_HEAD is set to the tip of the current branch. The <mode> must be one of the following (default --mixed ): --mixed Leave your working directory unchanged. Update the index to match the new HEAD , so nothing will be staged. If -N is specified, mark removed paths as intent-to-add (see git-add[1] ). --soft Leave your working tree files and the index unchanged. For example, if you have no staged changes, you can use git reset --soft HEAD~5; git commit to combine the last 5 commits into 1 commit.
This works even with changes in the working tree, which are left untouched, but such usage can lead to confusion. --hard Overwrite all files and directories with the version from <commit> , and may overwrite untracked files. Tracked files not in <commit> are removed so that the working tree matches <commit> . Update the index to match the new HEAD , so nothing will be staged. --merge Reset the index and update the files in the working tree that are different between <commit> and HEAD , but keep those which are different between the index and working tree (i.e. which have changes which have not been added).
Mainly exists to reset unmerged index entries, like those left behind by git am -3 or git switch -m in certain situations. If a file that is different between <commit> and the index has unstaged changes, reset is aborted. --keep Resets index entries and updates files in the working tree that are different between <commit> and HEAD . If a file that is different between <commit> and HEAD has local changes, reset is aborted. --recurse-submodules --no-recurse-submodules When the working tree is updated, using --recurse-submodules will also recursively reset the working tree of all active submodules according to the commit recorded in the superproject, also setting the submodules' HEAD to be detached at that commit. git reset [ -q ] [ <tree-ish> ] [ -- ] <pathspec> ... git reset [ -q ] [ --pathspec-from-file= <file> [ --pathspec-file-nul ]] [ <tree-ish> ] For all specified files or directories, set the staged version to the version from the given commit or tree (which defaults to HEAD ).
This means that git reset <pathspec> is the opposite of git add <pathspec> : it unstages all changes to the specified file(s) or directories. This is equivalent to git restore --staged <pathspec> ... . In this mode, git reset updates only the index (without updating the HEAD or working tree files). If you want to update the files as well as the index entries, use git-restore[1] . git reset ( --patch | -p ) [ <tree-ish> ] [ -- ] [ <pathspec> ...] Interactively select changes from the difference between the index and the specified commit or tree (which defaults to HEAD ).
The index is modified using the chosen changes. This means that git reset -p is the opposite of git add -p , i.e. you can use it to selectively unstage changes. See the "Interactive Mode" section of git-add[1] to learn how to use the --patch option. See "Reset, restore and revert" in git[1] for the differences between the three commands. OPTIONS -q --quiet Be quiet, only report errors. --refresh --no-refresh Refresh the index after a mixed reset.
Enabled by default. --pathspec-from-file= <file> Pathspec is passed in <file> instead of commandline args. If <file> is exactly - then standard input is used. Pathspec elements are separated by LF or CR / LF . Pathspec elements can be quoted as explained for the configuration variable core.quotePath (see git-config[1] ). See also --pathspec-file-nul and global --literal-pathspecs . --pathspec-file-nul Only meaningful with --pathspec-from-file .
Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes). -U <n> --unified= <n> Generate diffs with <n> lines of context. The number of context lines defaults to diff.context or 3 if the configuration variable is unset. ( -U without <n> is silently accepted as a synonym for -p due to a historical accident). --inter-hunk-context= <n> Show the context between diff hunks, up to the specified <number> of lines, thereby fusing hunks that are close to each other.
Defaults to diff.interHunkContext or 0 if the config option is unset. -- Do not interpret any more arguments as options. <pathspec> ... Limits the paths affected by the operation. For more details, see the pathspec entry in gitglossary[7] . EXAMPLES Undo add $ edit (1) $ git add frotz.c filfre.c $ mailx (2) $ git reset (3) $ git pull git://info.example.com/ nitfol (4) You are happily working on something, and find the changes in these files are in good order.
You do not want to see them when you run git diff , because you plan to work on other files and changes with these files are distracting. Somebody asks you to pull, and the changes sound worthy of merging. However, you already dirtied the index (i.e. your index does not match the HEAD commit). But you know the pull you are going to make does not affect frotz.c or filfre.c , so you revert the in
The rest of this page is on the live site.