git学习(2)

git log 查看版本历史记录

$ git log
$ git log
commit 3628164fb26d48395383f8f31179f24e0882e1e0
Author: Michael Liao 
Date:   Tue Aug 20 15:11:49 2013 +0800

    append GPL

commit ea34578d5496d7dd233c827ed32a8cd576c5ee85
Author: Michael Liao 
Date:   Tue Aug 20 14:53:12 2013 +0800

    add distributed

commit cb926e7ea50ad11b8f9e909c05226233bf755030
Author: Michael Liao 
Date:   Mon Aug 19 17:51:55 2013 +0800

    wrote a readme file

如果想看着舒服些,在命令的后面加上--pretty=oneline,每个版本就会变成一行显示

e418b7cc082755226ddfbf06eb32dc992af84e80 (HEAD -> master) oppend GPL
7fe71241ca64cb7d655857ca2f9d1ed3ee32bfb7 add distributed
00ea92d6ba067facbb05c3bd0bd983e375fa4eb5 wrote a test file
7104a61af27b76ce7b5a72cfeb287fc2f1166136 wrote a readme file
22b68df57eb2ac609719f560b41ca647f31160d6 wrote a readme file

git reset回滚历史版本

git里面有一个head指针,指着当前的版本

^指前一个版本,所以回滚到上一个版本的指令为git reset --hard head^ ,同理回滚到再之前的版本为^^,如果版本数量过多可以用数值代替head~100(回滚到第一百个版本)

$ git reset --hard head^
$ git reset --hard head~100

git reflog 查看回滚记录

$ git reflog
7fe7124 (HEAD -> master) HEAD@{0}: reset: moving to head^
e418b7c HEAD@{1}: reset: moving to e418b7cc0
7fe7124 (HEAD -> master) HEAD@{2}: reset: moving to head^
e418b7c HEAD@{3}: commit: oppend GPL
7fe7124 (HEAD -> master) HEAD@{4}: commit: add distributed
00ea92d HEAD@{5}: commit: wrote a test file
7104a61 HEAD@{6}: commit: wrote a readme file
22b68df HEAD@{7}: commit (initial): wrote a readme file

cat 查看当前文件内容

$ cat readme.txt
Rico:learngit rico$ cat readme.txt
Git is a distributed version control system.
Git is free software distributed under the GPL.

你可能感兴趣的:(git学习(2))