转载:https://www.liaoxuefeng.com/wiki/896043488029600/897013573512192
版本回退
修改redom.txt文件
版本1:wrote a readme file
Git is a version control system. Git is free software.
版本2:add distributed
Git is a distributed version control system. Git is free software.
版本3:append GPL
Git is a distributed version control system. Git is free software distributed under the GPL.
查看提交历史 $git log
$ git log commit 2de5fcfb77abef77a3715a5837884e0839427630 (HEAD -> master)Author: dream <又又ITDream@163.com> Date: Thu May 9 15:33:06 2019 +0800 append GPL commit 72d336879f4dcd4761b949a167dd95d7e4863840 Author: dream <又又ITDream@163.com> Date: Thu May 9 15:31:02 2019 +0800 distributed commit 58748418efa662590dd7b71a60dc3c68d24adaa1 Author: dream <又又ITDream@163.com> Date: Thu May 9 14:58:52 2019 +0800 worte a readme file
查看版本号:$git log --pretty== oneline
$ git log --pretty=oneline 2de5fcfb77abef77a3715a5837884e0839427630 (HEAD -> master) append GPL 72d336879f4dcd4761b949a167dd95d7e4863840 distributed 58748418efa662590dd7b71a60dc3c68d24adaa1 worte a readme file
2de5...是commit id(版本号,我们每个人的版本是不一样的) HEAD表示当前版本
回退版本:$git reset --hard HEAD^
$ git reset --hard HEAD^ HEAD is now at 72d3368 distributed
查看版本内容:$cat 文件名称
$ cat readme.txt
Git is a distributed version control system.
Git is free software.
指定回到未来某个版本:$git reset --hard 版本号(写几位即可)
$ git reset --hard 2de5f HEAD is now at 2de5fcf append GPL
查看命令历史:$ git reflog
$ git reflog 2de5fcf (HEAD -> master) HEAD@{0}: reset: moving to 2de5f 72d3368 HEAD@{1}: reset: moving to HEAD^ 2de5fcf (HEAD -> master) HEAD@{2}: commit: append GPL 72d3368 HEAD@{3}: commit: distributed 5874841 HEAD@{4}: reset: moving to HEAD^ 7911e59 HEAD@{5}: reset: moving to HEAD^ 808c93e HEAD@{6}: reset: moving to HEAD^ 9f92a21 HEAD@{7}: commit: append GPL 808c93e HEAD@{8}: commit: add distributed 7911e59 HEAD@{9}: commit: add 3 files 5874841 HEAD@{10}: commit (initial): worte a readme file