git reset改写提交

来源:互联网 发布:安卓游戏运行优化软件 编辑:程序博客网 时间:2024/06/05 05:11

教程3 改写提交!

3. reset

为了节省时间,这个教程使用现有的历史记录作为本地数据库。

从这里下载

我们将用reset来删除master分支最前面的两个提交。

首先进入stepup-tutorial/tutorial3目录。本地端的历史记录的状态如下图显示。

数据库的历史记录

用log命令确认历史记录。

$ git logcommit 0d4a808c26908cd5fe4b6294a00150342d1a58beAuthor: yourname <yourname@yourmail.com>Date:   Mon Jul 16 23:19:26 2012 +0900    添加pull的说明commit 9a54fd4dd22dbe22dd966581bc78e83f16cee1d7Author: yourname <yourname@yourmail.com>Date:   Mon Jul 16 23:19:01 2012 +0900    添加commit的说明commit 326fc9f70d022afdd31b0072dbbae003783d77edAuthor: yourname <yourname@yourmail.com>Date:   Mon Jul 16 23:17:56 2012 +0900    添加add的说明commit 48eec1ddf73a7fb508ef664efd6b3d873631742fAuthor: 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 logcommit 326fc9f70d022afdd31b0072dbbae003783d77edAuthor: yourname <yourname@yourmail.com>Date:   Mon Jul 16 23:17:56 2012 +0900    添加add的说明commit 48eec1ddf73a7fb508ef664efd6b3d873631742fAuthor: 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_HEADHEAD is now at 0d4a808 添加pull的说明
from: http://backlogtool.com/git-guide/cn/stepup/stepup7_3.html
0 0