Hongmu Notes

git reset

Untrack or cancel staging; reset the current Git HEAD to the specified state. If a file path is provided, execute "cancel staging"; if a commit hash or branch name is provided, execute "undo commit".

100% Browser local processing 0 Data upload

Common examples

Clear all files from temporary storage

git reset

Cancel temporary storage of specified files

git reset {{路径/到/文件1 路径/到/文件2 ...}}

Interactively cancel part of the temporarily stored file content

git reset {{[-p|--patch]}} {{路径/到/文件}}

Roll back the most recent commit while preserving its changes (as well as all uncommitted changes) in the workspace.

git reset HEAD~

Roll back the last two submissions and revert them to the staging area.

git reset --soft HEAD~2

Discard all uncommitted changes (including both staged and unstaged changes); to discard only unstaged changes, use `git checkout`.

git reset --hard

Reset the repository to the specified commit and discard all committed, staged, and unstaged changes made after that commit.

git reset --hard {{提交哈希}}

Tip: curly braces{{…}}It is the parameter that needs to be replaced (path, file name, etc.); the command is only executed in the local terminal, and this site does not save any input.

English original text comparison

Expand English instructions and examples (source tldr-pages)

Undo commits or unstage changes by resetting the current Git HEAD to the specified state. If a path is passed, it works as "unstage"; if a commit hash or branch is passed, it works as "uncommit". More information

Unstage everything

git reset

Unstage specific file(s)

git reset {{path/to/file1 path/to/file2 ...}}

Interactively unstage portions of a file

git reset {{[-p|--patch]}} {{path/to/file}}

Undo the last commit, keeping its changes (and any further uncommitted changes) in the filesystem

git reset HEAD~

Undo the last two commits, adding their changes to the index, i.e. staged for commit

git reset --soft HEAD~2

Discard any uncommitted changes, staged or not (for only unstaged changes, use `git checkout`)

git reset --hard

Reset the repository to a given commit, discarding committed, staged, and uncommitted changes since then

git reset --hard {{commit}}

command information

command namegit reset
PurposeUntrack or cancel staging; reset the current Git HEAD to the specified state. If a file path is provided, execute "cancel staging"; if a commit hash or branch name is provided, execute "undo commit".
Applicable platforms通用
Number of examples7 Article
Official documentationhttps://git-scm.com/docs/git-reset
Data sourcetldr-pages(CC-BY-4.0)· Community Chinese Translation

FAQ

git reset What does the command do?

Untrack or cancel staging; reset the current Git HEAD to the specified state. If a file path is provided, execute "cancel staging"; if a commit hash or branch name is provided, execute "undo commit".

git reset How to use it?

Pages listed by scene7Commonly used examples: Each example first explains the purpose, and then gives a complete command that can be directly copied (the parameters that need to be replaced are in the curly brackets).

git reset What are the most commonly used operations?

Clear all files from temporary storage:git reset

What do the curly braces in the command mean?

curly braces{{…}}Indicates that you need to replace it with your own value, such as path and file name; square brackets for parameters with the same name (such as[-C|--directory]) indicates optional writing.