reset --soft和--mixed之间的区别 [英] Difference between reset --soft and --mixed

查看:195
本文介绍了reset --soft和--mixed之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是GIT的新手,并试图了解git reset --softgit reset --mixed之间的区别.我知道后者会重设索引,而前者不会重设,但是我试图了解实质的区别是什么:何时将一个与另一个相对使用?

I'm new to GIT, and trying to understand the difference between git reset --soft and git reset --mixed. I know the latter resets the index, while the former does not, but I'm trying to understand what the material difference is: when would I use one versus the other?

我已阅读此Stack Overflow帖子,这似乎表明mixed倾向于在重新提交之前进行一些更改,而soft倾向于直接进行重新提交.我正在使用SourceTree,并关闭了暂存窗格,并努力查看为什么会这样.我一生无法看到任何 actual 真正的差异.

I've read this Stack Overflow post, which seems to suggest that mixed lends itself to making some changes before re-committing, while soft lends itself to simply re-committing immediately. I'm using SourceTree, with the staging pane turned off, and struggling to see why this is so; I can't for the life of me see any actual real differences.

我能看到的唯一区别是,我重置的新添加文件显示为带有软重置的添加,但混合时却不显示.但是无论哪种情况,我都可以成功地对新添加的文件进行更改,然后重新提交.当然,我对现有文件所做的任何新更改都会无缝添加到我当前未提交的更改中,随时可以提交.

The only difference I can see is that a newly added file that I reset over shows up as added with a soft reset, but not so with mixed. But in either case I can successfully make changes to the newly added file, and re-commit. And of course any new changes I make to existing files get seamlessly added to my current un-committed changes, ready to be committed.

我是否必须将暂存窗格"与源树"一起使用才能看到实际的区别,还是我只是缺少一些东西?明确地说,随着我现在如何设置工具,我看到了未提交的更改,这些更改是我一步完成的.

Do I have to use the Staging Pane with Source Tree to see any practical difference, or am I just missing something? To be clear, with how I have the tool set up now, I see un-committed changes, which I commit in one step.

推荐答案

如果您使用的.gitignore未被签入仓库或在提交之间更改,则将无法从中添加被忽略的文件.混合重置,除非手动进行,git diffgit status都不会显示它们在那里.

If you're using a .gitignore which is not checked into the repo or changed between the commits, you won't be able to add ignored files from a mixed reset except as manually, neither will git diff or git status show you they are there.

使用软重置,可以保证您进行的所有重置都将包含在提交中.

With a soft reset, everything you had reset will be guaranteed to be included into the commit should you make one.

实际上,这两种方法都是您需要的,这就是GIT中同时存在这两种方法(以及对索引本身的显式访问)的原因.

Actually, either of those might be the way you need, that's why both methods (and explicit access to the index itself) are there in GIT.

这篇关于reset --soft和--mixed之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆