如下,我们先多创建几个版本:
[[email protected] gitroot]# cat 1.txt 1111 2222 3333 [[email protected] gitroot]# echo "4444" >> 1.txt [[email protected] gitroot]# git add 1.txt [[email protected] gitroot]# git commit -m "add a line 4444" [[email protected] gitroot]# echo "5555" >> 1.txt [[email protected] gitroot]# git add 1.txt [[email protected] gitroot]# git commit -m "add a line 5555" [[email protected] gitroot]# echo "6666" >> 1.txt [[email protected] gitroot]# git add 1.txt [[email protected] gitroot]# git commit -m "add a line 6666" [[email protected] gitroot]# cat 1.txt 1111 2222 3333 4444 5555 6666
版本变更:
[[email protected] gitroot]# git log --pretty=oneline # 查看版本日志,前面一大串表示版本号,后面表示描述信息 5517ea21d60a2f79bff01a64143c6b229b44e331 add a line 6666 a28732896b2f00b3204f90e1a25030b984a06a56 add a line 5555 bb2b33017ca87389d30ab1b686ef1d5a5fb6128d add a line 4444 b0f13e12202543c859cba6fa8ceb3a88c4847f13 add new 1.txt [[email protected] gitroot]# git reset --hard bb2b330 # 根据版本号恢复到指定版本(不需要把一长串全部输入进来) [[email protected] gitroot]# cat 1.txt 1111 2222 3333 4444 [[email protected] gitroot]# git log --pretty=oneline # 这时候我们再查看版本日志,只剩两行,如果我们想查看完整的版本日志该怎么办 bb2b33017ca87389d30ab1b686ef1d5a5fb6128d add a line 4444 b0f13e12202543c859cba6fa8ceb3a88c4847f13 add new 1.txt [[email protected] gitroot]# git reflog # 查看完整的版本日志 5517ea2 [email protected]{8}: commit: add a line 6666 a287328 [email protected]{9}: commit: add a line 5555 bb2b330 [email protected]{10}: commit: add a line 4444 b0f13e1 [email protected]{11}: commit (initial): add new 1.txt
时间: 2024-11-05 16:31:25