下面对上次 readme.txt 做两次修改并提交
1.git is a distributed version control system 1.
git is free software 1.
2.git is a distributed version control system 2.
git is free software 2.
使用git log查看历史提交记录
D:\learngit>git log
commit 5d48c67818caa55cec7003f741f08c78841efea6 (HEAD -> master)
Author: zouyancheng <756587420@qq.com>
Date: Tue Jul 2 14:57:16 2019 +0800
four commit
commit 04c94d9da216e5a7fbed72c72a1f023dcf84bcd7
Author: zouyancheng <756587420@qq.com>
Date: Tue Jul 2 14:56:16 2019 +0800
tree commit
commit bcd07b190ebf04bdb9abc97f1bef6fb07057e268
Author: zouyancheng <756587420@qq.com>
Date: Tue Jul 2 14:47:15 2019 +0800
second commit
commit 054359e81a00d2b001e077868ef5168594445934
Author: zouyancheng <756587420@qq.com>
Date: Tue Jul 2 14:20:05 2019 +0800
first commit
如果嫌信息太乱可以使用这个命令
git log --pretty=oneline
D:\learngit>git log --pretty=oneline
5d48c67818caa55cec7003f741f08c78841efea6 (HEAD -> master) four commit
04c94d9da216e5a7fbed72c72a1f023dcf84bcd7 tree commit
bcd07b190ebf04bdb9abc97f1bef6fb07057e268 second commit
054359e81a00d2b001e077868ef5168594445934 first commit
现在如果将版本回退到上一个版本tree commit提交的那次可以使用 git reset --hard commitid
D:\learngit>git reset --hard 04c94d9da
HEAD is now at 04c94d9 tree commit
此时版本已经回退到tree commit那个版本
再使用git log
D:\learngit>git log
commit 04c94d9da216e5a7fbed72c72a1f023dcf84bcd7 (HEAD -> master)
Author: zouyancheng <756587420@qq.com>
Date: Tue Jul 2 14:56:16 2019 +0800
tree commit
commit bcd07b190ebf04bdb9abc97f1bef6fb07057e268
Author: zouyancheng <756587420@qq.com>
Date: Tue Jul 2 14:47:15 2019 +0800
second commit
commit 054359e81a00d2b001e077868ef5168594445934
Author: zouyancheng <756587420@qq.com>
Date: Tue Jul 2 14:20:05 2019 +0800
first commit
已经看不到four commit 那次的提交历史了
可以使用 git reflog 查看每一次命令
D:\learngit>git reflog
04c94d9 (HEAD -> master) HEAD@{0}: reset: moving to 04c94d9da
5d48c67 HEAD@{1}: commit: four commit
04c94d9 (HEAD -> master) HEAD@{2}: commit: tree commit
bcd07b1 HEAD@{3}: commit: second commit
054359e HEAD@{4}: commit (initial): first commit
使用 git reset --hard 5d48c67即可回到未来的版本