git 重置命令
Git重置 (Git Reset)
The git reset
command allows you to RESET your current head to a specified state. You can reset the state of specific files as well as an entire branch.
git reset
命令允许您将当前磁头重置为指定状态。 您可以重置特定文件以及整个分支的状态。
重置一个文件或一组文件 (Reset a file or set of files)
The following command lets you selectively choose chunks of content and revert or unstage it.
以下命令使您可以有选择地选择大块内容并还原或取消登台。
git reset (--patch | -p) [tree-ish] [--] [paths]
取消暂存文件 (Unstage a file)
If you moved a file into the staging area with git add
, but no longer want it to be part of a commit, you can use git reset
to unstage that file:
如果您使用git add
文件移到暂存区域,但不再希望其成为提交的一部分,则可以使用git reset
取消git reset
该文件:
git reset HEAD FILE-TO-UNSTAGE
The changes you made will still be in the file, this command just removes that file from your staging area.
您所做的更改仍将保留在文件中,此命令只是从暂存区中删除该文件。
将分支重置为先前的提交 (Reset a branch to a prior commit)
The following command resets your current branch’s HEAD to the given COMMIT
and updates the index. It basically rewinds the state of your branch, then all commits you make going forward write over anything that came after the reset point. If you omit the MODE
, it defaults to --mixed
:
以下命令将当前分支的HEAD重置为给定的COMMIT
并更新索引。 它基本上倒退了分支的状态,然后进行的所有提交都将覆盖重置点之后的所有内容。 如果省略MODE
,则默认为--mixed
:
git reset MODE COMMIT
The options for MODE
are:
MODE
的选项为:
--soft
: does not reset the index file or working tree, but resets HEAD tocommit
. Changes all files to “Changes to be commited”--soft
:不重置索引文件或工作树,但将HEAD重置为commit
。 将所有文件更改为“要提交的更改”--mixed
: resets the index but not the working tree and reports what has not been updated--mixed
:重置索引,但不重置工作树,并报告尚未更新的内容--hard
: resets the index and working tree. Any changes to tracked files in the working tree sincecommit
are discarded--hard
:重置索引和工作树。 自commit
以来对工作树中跟踪文件的任何更改都将被丢弃--merge
: resets the index and updates the files in the working tree that are different betweencommit
and HEAD, but keeps those which are different between the index and working tree--merge
:重置索引并更新工作树中commit
和HEAD之间不同的文件,但保留那些索引和工作树之间不同的文件--keep
: resets index entries and updates files in the working tree that are different betweencommit
and HEAD. If a file that is different betweencommit
and HEAD has local changes, the reset is aborted--keep
:重置索引条目并更新工作树中commit
和HEAD之间不同的文件。 如果commit
和HEAD之间的文件不同,则具有本地更改,则重置将中止
翻译自: https://www.freecodecamp.org/news/the-git-reset-command/
git 重置命令