跳转至

8. git版本控制

8. git版本控制

8.1 版本回退

1.查看版本
[root@chupeng git03]# git log --oneline
7c3cdf0 第五次提交
435af0c 第四次提交
114ca40 第三次提交
ccb7f10 第二次提交
3679d4b 第一版的注释信息
[root@chupeng git03]# ls
a_v1  a_v2  b_v2
2.回退到第二次提交
[root@chupeng git03]# git reset --hard ccb7f10
HEAD is now at ccb7f10 第二次提交
[root@chupeng git03]# git log --oneline
ccb7f10 第二次提交
3679d4b 第一版的注释信息
[root@chupeng git03]# ls
a_v1  c_v1
3.回到上一个版本
[root@chupeng git03]# git reset --hard HEAD^
HEAD is now at 3679d4b 第一版的注释信息
[root@chupeng git03]# git log --oneline
3679d4b 第一版的注释信息
[root@chupeng git03]# ls
a_v1  b_v1

8.2 版本最新

1.查看所有版本变动
[root@chupeng git03]# git reflog
3679d4b HEAD@{0}: reset: moving to HEAD^
ccb7f10 HEAD@{1}: reset: moving to ccb7f10
7c3cdf0 HEAD@{2}: commit: 第五次提交
435af0c HEAD@{3}: commit: 第四次提交
114ca40 HEAD@{4}: commit: 第三次提交
ccb7f10 HEAD@{5}: commit: 第二次提交
3679d4b HEAD@{6}: commit (initial): 第一版的注释信息
2.回到第五次提交的版本
[root@chupeng git03]# git reset --hard 7c3cdf0
HEAD is now at 7c3cdf0 第五次提交
[root@chupeng git03]# git log --oneline
7c3cdf0 第五次提交
435af0c 第四次提交
114ca40 第三次提交
ccb7f10 第二次提交
3679d4b 第一版的注释信息
[root@chupeng git03]# ls
a_v1  a_v2  b_v2

最后更新: 2022-02-18 11:26:47