git 重置命令_Git重置命令

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 to commit. 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 since commit are discarded

    --hard :重置索引和工作树。 自commit以来对工作树中跟踪文件的任何更改都将被丢弃

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

    --merge :重置索引并更新工作树中commit和HEAD之间不同的文件,但保留那些索引和工作树之间不同的文件

  • --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, the reset is aborted

    --keep :重置索引条目并更新工作树中commit和HEAD之间不同的文件。 如果commit和HEAD之间的文件不同,则具有本地更改,则重置将中止

翻译自: https://www.freecodecamp.org/news/the-git-reset-command/

git 重置命令

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值