https://stackoverflow.com/questions/3528245/whats-the-difference-between-git-reset-mixed-soft-and-hard

When you modify a file in your repository, the change is initially unstaged. In order to commit it, you must stage it—that is, add it to the index—using git add. When you make a commit, the changes that are committed are those that have been added to the index.

git reset changes, at minimum, where the current branch (HEAD) is pointing. The difference between --mixed and --soft is whether or not your index is also modified. So, if we're on branch master with this series of commits:

- A - B - C (master)

HEAD points to C and the index matches C.

When we run git reset --soft B, master (and thus HEAD) now points to B, but the index still has the changes from C; git status will show them as staged. So if we run git commit at this point, we'll get a new commit with the same changes as C.


Okay, so starting from here again:

- A - B - C (master)

Now let's do git reset --mixed B. (Note: --mixed is the default option). Once again, master and HEAD point to B, but this time the index is also modified to match B. If we run git commit at this point, nothing will happen since the index matches HEAD. We still have the changes in the working directory, but since they're not in the index, git status shows them as unstaged. To commit them, you would git add and then commit as usual.


And finally, --hard is the same as --mixed (it changes your HEAD and index), except that --hard also modifies your working directory. If we're at C and run git reset --hard B, then the changes added in C, as well as any uncommitted changes you have, will be removed, and the files in your working copy will match commit B. Since you can permanently lose changes this way, you should always run git status before doing a hard reset to make sure your working directory is clean or that you're okay with losing your uncommitted changes.

总结:

假设有A<--B<--C 三个commit,当前分支master指向C【先确保本地是clean的状态】

执行git reset --soft B,本地文件变成修改状态,并且是B到C的变化。

执行 git reset --mixed B,master指向B,并且文件work directory的文件内容会切换到B所在的状态

想到了关于soft的使用,如果在回滚之后,进行commit。其实就相当于一次squash

最新文章

  1. angular学习笔记(二十八)-$http(6)-使用ngResource模块构建RESTful架构
  2. Jquery判断变量是否为空
  3. IE6 IE7 ‘JSON’ 未定义
  4. js实现web网页版台球游戏
  5. 一段关于测试和自定义Attribute的代码
  6. xamarin UWP平台下 HUD 自定义弹窗
  7. [BZOJ2038]小Z的袜子(莫队算法)
  8. jboss4.2.3建立oracle JMS应用
  9. Ubuntu下Code::Blocks无法编译 /bin/sh: 1: g++ not found 解决办法
  10. ECSHOP报错误Deprecated: preg_replace(): The /e modifier is depr
  11. div+css3列布局,带详尽注释
  12. Java学习----Java程序结构
  13. Android(java)学习笔记253:ContentProvider使用之内容观察者02
  14. HDU4532(组合DP)
  15. 购物车CheckBox全选、反选
  16. java_web学习(2)Servlet
  17. 201521123039《java程序设计》第五周学习总结
  18. UITextFiled的输入框改成一条下划线
  19. poj2029 Get Many Persimmon Trees
  20. How to preview html file in our browser at sublime text?

热门文章

  1. 有趣的console
  2. BZOJ 2741 L (可持久化01Trie+分块)
  3. CF1029E Tree with Small Distances (贪心)
  4. Springboot - -web应用开发-Servlets, Filters, listeners
  5. iOS基础UI控件介绍-Swift版
  6. 题解 洛谷 P3381 【【模板】最小费用最大流】
  7. Java集合源代码剖析(一)【集合框架概述、ArrayList、LinkedList、Vector】
  8. php通过shell调用Hadoop的方法
  9. 【C#】报表制作&amp;lt;机房重构&amp;gt;
  10. IIS访问站点,出现connection refused