← 返回命令列表

Linux command

git-reset 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Unstage files

git reset [file]

Soft reset (keep changes staged)

git reset --soft [commit]

Mixed reset (unstage changes)

git reset [commit]

Hard reset (discard changes)

git reset --hard [commit]

Reset to upstream

git reset --hard @{u}

Unstage all files

git reset HEAD

Reset single file to commit

git reset [commit] -- [file]

说明

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.

参数

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

FAQ

What is the git-reset command used for?

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.

How do I run a basic git-reset example?

Run `git reset [file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --soft do in git-reset?

Keep changes staged.