LinuxCommandLibrary

git-reset

Reset current HEAD to a specified state

TLDR

Unstage files

$ git reset [file]
copy
Soft reset (keep changes staged)
$ git reset --soft [commit]
copy
Mixed reset (unstage changes)
$ git reset [commit]
copy
Hard reset (discard changes)
$ git reset --hard [commit]
copy
Reset to upstream
$ git reset --hard @{u}
copy
Unstage all files
$ git reset HEAD
copy
Reset single file to commit
$ git reset [commit] -- [file]
copy

SYNOPSIS

git reset [options] [commit] [--] [files...]

DESCRIPTION

git reset moves the current HEAD to a specified state. It can unstage files, undo commits, or completely discard changes depending on the mode used.
The three main modes are `--soft` (keeps changes staged), `--mixed` (unstages changes, the default), and `--hard` (discards all changes). When given file paths, it unstages those files without moving HEAD.

PARAMETERS

--soft

Keep changes staged.
--mixed
Unstage changes (default).
--hard
Discard all changes.
--keep
Reset but keep local changes.
--merge
Reset to merge state.
-p, --patch
Interactive reset.

CAVEATS

Hard reset discards changes permanently. Be careful with --hard on uncommitted work.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community