教程3 改写提交!
3. reset
为了节省时间,这个教程使用现有的历史记录作为本地数据库。
从这里下载
我们将用reset来删除master分支最前面的两个提交。
首先进入stepup-tutorial/tutorial3目录。本地端的历史记录的状态如下图显示。
用log命令确认历史记录。
$ git log
commit 0d4a808c26908cd5fe4b6294a00150342d1a58be
Author: yourname <yourname@yourmail.com>
Date: Mon Jul 16 23:19:26 2012 +0900
添加pull的说明
commit 9a54fd4dd22dbe22dd966581bc78e83f16cee1d7
Author: yourname <yourname@yourmail.com>
Date: Mon Jul 16 23:19:01 2012 +0900
添加commit的说明
commit 326fc9f70d022afdd31b0072dbbae003783d77ed
Author: yourname <yourname@yourmail.com>
Date: Mon Jul 16 23:17:56 2012 +0900
添加add的说明
commit 48eec1ddf73a7fb508ef664efd6b3d873631742f
Author: yourname <yourname@yourmail.com>
Date: Mon Jul 16 23:16:14 2012 +0900
first commit
打开sample.txt档案,确认内容。
连猴子都懂的Git命令 add 把变更录入到索引中 commit 记录索引的状态 pull 取得远端数据库的内容
用reset删除提交。
$ git reset --hard HEAD~~
HEAD is now at 326fc9f 添加add的说明
打开sample.txt,看看「添加commit的讲解」和「添加pull的讲解」是否消失了。或者用log命令确认历史记录。
$ git log
commit 326fc9f70d022afdd31b0072dbbae003783d77ed
Author: yourname <yourname@yourmail.com>
Date: Mon Jul 16 23:17:56 2012 +0900
添加add的说明
commit 48eec1ddf73a7fb508ef664efd6b3d873631742f
Author: yourname <yourname@yourmail.com>
Date: Mon Jul 16 23:16:14 2012 +0900
first commit
在reset之前的提交可以参照ORIG_HEAD。Reset错误的时候,在ORIG_HEAD上reset 就可以还原到reset前的状态。
$ git reset --hard ORIG_HEAD
HEAD is now at 0d4a808 添加pull的说明
from: http://backlogtool.com/git-guide/cn/stepup/stepup7_3.html