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)

HEADpoints 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.

Whats the difference between git reset --mixed, --soft, and --hard?相关推荐

  1. git reset hard/soft/mixed区别

    git reset hard/soft/mixed区别 git reset --soft git reset --mixed或者 git reset (默认是git reset --mixed) gi ...

  2. git reset --mixed, - soft和--hard有什么区别?

    我希望拆分提交,不知道要使用哪个重置选项. 我在看页面你能解释一下"git reset"用简单的英语做什么吗? ,但我意识到我并不真正理解git索引或临时区域是什么,因此解释没有帮 ...

  3. git reset --hard --soft 与 git revert 的作用

    1.git reset --hard --soft 与 git revert 的作用: 文件从暂存区回退到工作区 版本回退 2.git简单的分为三个区域 : 1.工作区(working directo ...

  4. 一文搞懂本地和远程分支代码回退git reset

    最近痴迷于git flow,打算对之前大部分人一提起就害怕的代码回退--git reset来进行一个实践,也算是一篇操作总结,想直接看结论的可以拉到文末,如有纰漏,欢迎大佬们指正补充. git进阶之路 ...

  5. git reset soft、mixed和hard的区别和用途详讲

    先看看工作区.暂存区和本地版本库的关系 你的项目就在工作区,对于项目新建的文件你必须先add保存到暂存区,再commit提交到本地库: 对于修改的文件可以先add再commit,或者直接commit. ...

  6. git版本回退–soft –mixed –hard的区别

    这周上班的时候,一个同事发了一个如下的截图问我IDEA的代码回滚这三种操作有什么区别?当时也回答得寥寥草草的,平时用hard比较多也没太注意这个细节,所以写篇文章记录一下,也希望能帮助到大家. 实际上 ...

  7. git reset简介

    本文编辑整理自:http://guibin.iteye.com/blog/1014369 http://hi.baidu.com/tiger_tnt/blog/item/a0464ffa6a8115d ...

  8. Git reset , revert, checkout的区别和联系

    转自: http://www.cnblogs.com/houpeiyong/p/5890748.html 拿来做个笔记 git reset.git checkout和git revert是你的Git工 ...

  9. git reset revert 回退回滚取消提交返回上一版本

    总有一天你会遇到下面的问题. (1)改完代码匆忙提交,上线发现有问题,怎么办? 赶紧回滚. (2)改完代码测试也没有问题,但是上线发现你的修改影响了之前运行正常的代码报错,必须回滚. 这些开发中很常见 ...

最新文章

  1. AttributeError:module“seaborn” has no attribute “lineplot”
  2. 对Dev的GridControl/GridView控件进行分组并展开操作
  3. 分布式锁的三种实现的对比
  4. 【Spring学习】IoC、DI、AOP入门学习
  5. Android官方开发文档Training系列课程中文版:数据存储之键值对序列存储
  6. java引用公共类_使用键引用从Java公共类获取值 - java
  7. AI为移动医疗APP加码,智能提醒你:该吃药了!
  8. wifi控制基于STM32与NFC的万能红外遥控器—毕业设计(2)
  9. 设计模式:责任链模式
  10. 漂亮女人美丽秘诀------猕猴桃(奇异果)
  11. gcc -wall -pedantic -ansi
  12. 时尚漂亮的充电头,苹果安卓都能用,Anker安芯充20W上手
  13. 吴晓波:拼多多的新与旧
  14. play框架用起来(3)
  15. 在智能手机上跟踪ADS-B系统的飞机航线信息
  16. normal模式/loader模式/MASKROM模式
  17. 如何用Matlab做一个3D头像
  18. 9 EDA实用技术与教程【Verilog深入】
  19. 电商网站适合用什么服务器?
  20. 我们可以从挑战者灾难中学到什么关于网络安全的知识?一切。

热门文章

  1. 7-9 用天平找小球 (10 分)
  2. c语言能让制表符空9个字符码,C语言入门9-1-分类函数
  3. 3001基于哈夫曼树的数据压缩算法(附思路及注释)
  4. 嵌入式入门之烧录操作系统
  5. Linux netstat命令详解和使用例子(显示各种网络相关信息)
  6. 学习笔记12JS异步请求
  7. [转载] 深入理解Linux修改hostname
  8. VS2010可反复安装MSDN的方法
  9. linux下 apache启动、停止、重启命令
  10. Android开发之TextView排版问题