git reset hard/mixed/soft三种模式详解

本文深入解析Git中reset命令的三种模式:soft、mixed和hard。通过实际操作和状态展示,帮助读者理解不同模式下如何处理工作区和暂存区的变更。

请在你的git bash输入如下命令,此时会在你的浏览器弹出一个关于git reset详解的html页面。其实这个html就在你的本地,顺腾摸瓜,可以在此路径下面找到其它的一些命令教程。

git reset --help

暂且只讨论下面的用法,soft,mixed,hard。请将下面的英文解释多看几遍,可以自行google翻译。

git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]

--soft
Does not touch the index file or the working tree at all (but resets the head to <commit>, just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.

--mixed
Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.

If -N is specified, removed paths are marked as intent-to-add (see git-add(1)).

--hard
Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.

理解上图中的关系,多看几遍英文解释,多动手操作几遍。下面是我的理解。

hard:将HEAD之后的变更内容全部丢弃。

mixed:将HEAD之后的变更内容放到工作区中

soft:代表将HEAD之后的变更内容放到暂存区中。

以下下三个图均在我当前HEAD中,将test.txt添加到了暂存区,但是没有提交的条件下执行的。不用关注我过程修改的内容,你只需要关注当我执行了mixed/soft/hard之后,使用git status查看的状态。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值