【转】git reset 之 soft mixed hard选项的区别

来源:互联网 发布:代谢综合征数据库 编辑:程序博客网 时间:2024/05/21 10:32


Parameters

reset命令本身很简单,但是它的参数让人迷惑,主要的参数有soft, hard and mixed,它们告诉Git,当执行reset时,要对index和working copy做什么。

So the reset command itself is pretty simple, but it’s the parameters that cause confusion. The main parameters aresoft, hard and mixed. These tell Git what to do with your index and working copy when performing the reset.


Soft

The --soft参数只告诉Git将其他的commit重置到HEAD,就仅此而已。index和working copy中的文件都不改变。

parameter tells Git to reset HEAD to another commit, but that’s it. If you specify--soft Git will stop there and nothing else will change. What this means is that the index and working copy don’t get touched, so all of the files that changed between the original HEAD and the commit you reset to appear to be staged.

reset-wc-index-changed

Mixed (default)

The --mixed 改变HEAD和index,指向那个你要reset到的commit上。而working copy文件不被改变。当然会显示工作目录下有修改,但没有缓存到index中。

parameter (which is the default if you don’t specify anything) will reset HEAD to another commit,and will reset the index to match it, but will stop there. The working copy will not be touched. So, all of the changes between the original HEAD and the commit you reset to are still in the working copy and appear as modified, but not staged.

reset-wc-changed

Hard

The --hard HEAD & index & working copy同时改变到你要reset到的那个commit上。这个参数很危险,执行了它,你的本地修改可能就丢失了。

parameter will blow out everything – it resets HEAD back to another commit, resets the index to match it,and resets the working copy to match it as well. This is the more dangerous of the commands and is where you can cause damage. Data might get lost here*!

reset-all-happy


可以用git reflog命令查看coomit ID,恢复到reset之前的状态。
* You can recover it using git reflog but that’s out of scope here.

1 0
原创粉丝点击