git版本变更
2020-02-07Linux90root555°c
A+ A-对现有的版本进行更改(比如我取消了一些内容)
[[email protected] gitroot]# ls 666.txt [[email protected] gitroot]# vim 666.txt sd5 da5
提交新改的版本
[[email protected] gitroot]# git add 666.txt [[email protected] gitroot]# git commit -m "change 666.txt agin" [master e724a2b] change 666.txt agin 1 files changed, 2 insertions(+), 7 deletions(-)
再次更改版本内容
[[email protected] gitroot]# vim 666.txt d55555asdas sdasd5s5 1111111
提交到版本库
[[email protected] gitroot]# git add 666.txt [[email protected] gitroot]# git commit -m "change 666.txt agin gz" [master 8803cdf] change 666.txt agin gz 1 files changed, 1 insertions(+), 1 deletions(-)
查看曾经提交过的版本
[[email protected] gitroot]# git log commit 8803cdf74873fe868488ff628706607bea8432b8 Author: azhen <[email protected]> Date: Fri Sep 16 22:55:55 2016 +0800 change 666.txt agin gz commit e724a2b5359b232aa80b8a5ee76306b0563e500e Author: azhen <[email protected]> Date: Fri Sep 16 22:52:51 2016 +0800 change 666.txt agin commit 35c58c59fba75e0127b4e32bde4f395317207c39 Author: azhen <[email protected]> Date: Fri Sep 16 22:29:49 2016 +0800 add a line nue commit d52feeae1b4465030218c9289f9d5f9c9008b463 Author: azhen <[email protected]> Date: Fri Sep 16 22:03:16 2016 +0800 add good 666.txt
可以看出上面的版本太多,有点乱,我们用一行进行显示(前面版本号后面是描述)
[[email protected] gitroot]# git log --pretty=oneline 8803cdf74873fe868488ff628706607bea8432b8 change 666.txt agin gz e724a2b5359b232aa80b8a5ee76306b0563e500e change 666.txt agin 35c58c59fba75e0127b4e32bde4f395317207c39 add a line nue d52feeae1b4465030218c9289f9d5f9c9008b463 add good 666.txt
通过git log我们可以查看到过去提交的所有版本,所以根据这个log,我们可以指定回退某个版本比如,结果如下
[[email protected] gitroot]# git reset --hard d52fe HEAD is now at d52feea add good 666.txt
注释–herd 后面是 历史版本倒数第一个的前五位版本号
经查看已经恢复到第一次的版本
[[email protected] gitroot]# cat 666.txt dasdas sdasd asdas das da sd as d
再次查看历史版本,只显示一个历史版本,如果想回退到其他版本咋办呢?
[[email protected] gitroot]# git reflog #显示所有版本 d52feea [email protected]{0}: d52fe: updating HEAD 8803cdf [email protected]{1}: commit: change 666.txt agin gz e724a2b [email protected]{2}: commit: change 666.txt agin 35c58c5 [email protected]{3}: commit: add a line nue
回退到倒数第三个版本
[[email protected] gitroot]# git reset --hard 8803cdf HEAD is now at 8803cdf change 666.txt agin gz [[email protected] gitroot]# cat 666.txt d55555asdas sdasd5s5 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
标签:Git