标签:des style blog http color io os ar 使用
涉及Git一些日常操作 :)
《Pro Git》至少了解branch,commit的概念,及基本的原理
暂存区(stage, index)是 Git 最重要的概念之一
这样的引用标识符——它看起来并不像一个普通的引用——其实并不包含 SHA-1 值,而是一个指向另外一个引用的指针。内容如下
HEAD~n
表示从当前HEAD指向的commit开始数的第几个(参见git log HEAD或git log)
从0开始计数,git log中第一个commit 表示HEAD~0
下面这段话非常重要
git reset [<mode>] [<commit>] This form resets the current branch head to <commit> and possibly updates the index (resetting it to the tree of <commit>) and the working tree depending on <mode>. !!!!!! If <mode> is omitted, defaults to "--mixed". The <mode> must be one of the following: --soft Does not touch the index file nor 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. --hard Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded. --merge Resets the index and updates the files in the working tree that are different between <commit> and HEAD, but keeps those which are different between the index and working tree (i.e. which have changes which have not been added). If a file that is different between <commit> and the index has unstaged changes, reset is aborted. In other words, --merge does something like a git read-tree -u -m <commit>, but carries forward unmerged index entries. --keep Resets index entries and updates files in the working tree that are different between <commit> and HEAD. If a file that is different between <commit> and HEAD has local changes, reset is aborted. !!!If you want to undo a commit other than the latest on a branch, git-revert(1) is your friend.
将当前的branch head重置到某个commit上面,这可能会影响index(暂存)区域。
默认情况下使用--mixed形式`
注意,暂时只关注soft, mixed, hard,另外还有两种是merge和keep
working index HEAD target working index HEAD
----------------------------------------------------
A B C D --soft A B D
--mixed A D D
--hard D D D
git reset HEAD (该命令会改变index与HEAD,使得文件状态变成unstage)
如下图所示:默认情况下,HEAD可以不写。
该命令可以完整的写法是git reset HEAD~0 --mixed
解释为重定向到这次的提交
working index HEAD target working index HEAD
----------------------------------------------------
A B C C --mixed A C C
另外,从上面看来,值得注意的是以下写法是等同的
git reset HEAD~1 --mixed
解释为重定位到上次提交
(该命令会改变index与HEAD,使得文件状态变成unstage)
working index HEAD target working index HEAD
----------------------------------------------------
A B C D --mixed A D D
如果想完全忽略这次commit编辑的内容
1. 可以继续使用 git checkout – . 清除所有与index(此时index已经等于上次commit)不同的改变
2. 或者直接使用 git reset HEAD~1 --hard
简单来说,执行某次commit操作的逆向操作,并且提交(默认提交)。
通常情况下,QA大叫出事啦出事啦,回滚回滚。意思是线上项目的回滚而非代码的回滚。(当然最好还是问清楚是不是这样)
主线源代码回滚,能做是能做,但比较麻烦。所以先case by case考察一下必要性。线上回滚,并不意味着源代码一定要回滚。下面这些情况就不用回滚:
只有当要修正前次失败的发布中的错误需要较长时间,而同时又有其他new feature或bug fix着急上线时,才需要主线上的源代码回滚。
不论是使用reset还是使用revert都会带来不同程度的麻烦
Reset比revert会带来更多地麻烦。情况会非常复杂。
我们系统中使用revert。
已经merge master的开发分支,只需要继续merge master即可(此次回滚完全不可见)
当前开发(正在发布的),需要merge master之后 revert掉master上revert的那次commit
标签:des style blog http color io os ar 使用
原文地址:http://www.cnblogs.com/maxmys/p/4032428.html