Home Explore Blog CI



git

2nd chunk of `Documentation/git-reset.adoc`
482fa792d6f23e573afb0c7b83dbd3c381f3eeb20e8b00640000000100000fa2
 writing any tracked files are simply deleted.

`--merge`::
	Resets the index and updates the files in the working tree that are
	different between _<commit>_ and `HEAD`, but keeps those which are
	different between the index and working tree (i.e. which have changes
	which have not been added).
	If a file that is different between _<commit>_ and the index has
	unstaged changes, reset is aborted.
+
In other words, `--merge` does something like a `git read-tree -u -m <commit>`,
but carries forward unmerged index entries.

`--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.

`--[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.
--

See "Reset, restore and revert" in linkgit: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 linkgit: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).

`--`::
	Do not interpret any more arguments as options.

`<pathspec>...`::
	Limits the paths affected by the operation.
+
For more details, see the 'pathspec' entry in linkgit: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>
------------
+
<1> 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.
<2> Somebody asks you to pull, and the changes sound worthy of merging.
<3> 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
    index changes for these two files.  Your changes in working tree
    remain there.
<4> Then you can pull and merge, leaving `frotz.c` and `filfre.c`
    changes still in the working tree.

Undo a commit and redo::
+
------------
$ git commit ...
$ git reset --soft HEAD^      <1>
$ edit                        <2>
$ git commit -a -c ORIG_HEAD  <3>
------------
+
<1> This is most often done when you remembered what you
    just committed is incomplete, or you misspelled your commit
    message, or both.  Leaves working tree as it was before "reset".
<2> Make corrections to working tree files.
<3> "reset" copies the old head to `.git/ORIG_HEAD`; redo the
    commit by starting with its log message.  If you do not need to
    edit the message further, you can give `-C` option instead.
+
See also the `--amend` option to linkgit:git-commit[1].

Undo a commit, making it a topic branch::
+
------------
$ git branch topic/wip          <1>
$ git reset --hard HEAD~3       <2>
$ git switch topic/wip          <3>
------------
+
<1> You have made some commits, but realize they were premature
    to be

Title: Git Reset Options and Examples
Summary
The git reset command has various options, including --merge, --keep, and --recurse-submodules, which allow for different types of resets, and can be used in different scenarios, such as undoing adds, commits, and making topic branches, with examples provided to illustrate its usage.