Git教程学习(二)

教程来自: Git教程(廖雪峰的官方网站)

主要命令:

$ git log  #查看已提交内容
$ git log --pretty=oneline  #查看已提交内容(紧凑版)

$ git reset --hard HEAD^  #回退到上一版本
$ git reset --hard 3628164  #回退到版本3628164

$ git reflog  #查看提交过的命令


5. 版本回退

5.1 repo会记录每次提交的版本,用户也可以随时回退到任何版本.比如以下三个readme.txt版本

版本1:wrote a readme file

Git is a version control system.
Git is free software.

版本2:add distributed

Git is a distributed version control system.
Git is free software.

版本3:append GPL

Git is a distributed version control system.
Git is free software distributed under the GPL.

5.2. 如果记不清各个版本了可以使用git log来查看版本提交时的comment,也就是-m参数后的string

$ git log
commit 3628164fb26d48395383f8f31179f24e0882e1e0
Author: Michael Liao <askxuefeng@gmail.com>
Date:   Tue Aug 20 15:11:49 2013 +0800

    append GPL

commit ea34578d5496d7dd233c827ed32a8cd576c5ee85
Author: Michael Liao <askxuefeng@gmail.com>
Date:   Tue Aug 20 14:53:12 2013 +0800

    add distributed

commit cb926e7ea50ad11b8f9e909c05226233bf755030
Author: Michael Liao <askxuefeng@gmail.com>
Date:   Mon Aug 19 17:51:55 2013 +0800

    wrote a readme file

5.3. 回退有两种方式:

5.3.1. 回退到上一版本

$ git reset --hard HEAD^
HEAD is now at ea34578 add distributed

5.3.2. 回退到指定版本(通过commit id)

$ git reset --hard 3628164
HEAD is now at 3628164 append GPL

5.4. 如果不记得commit id,可以使用git reflog查询提交版本的历史记录

$ git reflog
ea34578 HEAD@{0}: reset: moving to HEAD^
3628164 HEAD@{1}: commit: append GPL
ea34578 HEAD@{2}: commit: add distributed
cb926e7 HEAD@{3}: commit (initial): wrote a readme file

6. 工作区和暂存区

工作区指写代码的目录,工作区有一个隐藏目录.git,是git的版本库

版本库中有stage区和master区,分别为暂存区和主分支

  stage中存放git add中修改的内容

  master中存放当前版本的内容

git commit就是把stage中的修改应用到master中去

posted on 2015-07-02 22:10  york_hust  阅读(404)  评论(0编辑  收藏  举报