git学习02 - log查看&版本回退

1、查看更新记录 git log /  git log --pretty=oneline

D:\learn\git_test>git log
commit a915e7b12076673d778da2abad8d7b11b681d88d (HEAD -> master)
Author: xiong <[email protected]>
Date:   Tue Apr 23 19:03:24 2019 +0800

    add a distributed word

commit eaf3eea813568389f0213eb56f1ac8456b0c6fb8
Author: xiong <[email protected]>
Date:   Tue Apr 23 18:47:42 2019 +0800

    wrote a readme file
############################################
D:\learn\git_test>git log --pretty=oneline a915e7b12076673d778da2abad8d7b11b681d88d (HEAD -> master) add a distributed word eaf3eea813568389f0213eb56f1ac8456b0c6fb8 wrote a readme file

  其中,前面的一串很长的数字为sha1算法计算得来的commit id,是每一个版本的唯一标识,若需要回退时则需要使用

  HEAD 代表为当前版本

2、回退版本 git reset --hard commit-id

D:\learn\git_test>git log --pretty=oneline
a915e7b12076673d778da2abad8d7b11b681d88d (HEAD -> master) add a distributed word
eaf3eea813568389f0213eb56f1ac8456b0c6fb8 wrote a readme file

D:\learn\git_test>git reset --hard eaf3
HEAD is now at eaf3eea wrote a readme file

D:\learn\git_test>git log --pretty=oneline
eaf3eea813568389f0213eb56f1ac8456b0c6fb8 (HEAD -> master) wrote a readme file

D:\learn\git_test>type readme.txt
Git is a version control system
Git is a free software

  commit-id可以简写,git可自动找到该版本

       若由较新的版本更新为旧版本,则再使用git log时看不到新版本的信息

3、若想再更新到原来的新版本 通过 git reflog 找到原版本的commit-id,再执行reset即可

D:\learn\git_test>git reflog
eaf3eea (HEAD -> master) HEAD@{0}: reset: moving to eaf3
a915e7b HEAD@{1}: reset: moving to HEAD
a915e7b HEAD@{2}: commit: add a distributed word
eaf3eea (HEAD -> master) HEAD@{3}: commit (initial): wrote a readme file

D:\learn\git_test>git reset --hard a915e7b
HEAD is now at a915e7b add a distributed word

D:\learn\git_test>type readme.txt
Git is a distributed version control system
Git is a free software

  

猜你喜欢

转载自www.cnblogs.com/minx555/p/10758474.html