情况三:已经 add ,并且也 commit 了
情况三:已经 add ,并且也 commit 了
不要担⼼,我们可以 git reset --hard HEAD^ 回退到上⼀个版本!不过,这是有条件的,就是你还没有把⾃⼰的本地版本库推送到远程。还记得Git是分布式版本控制系统吗?我们后⾯会讲到远程版本库,⼀旦你推送到远程版本库,你就真的惨了……
root@hcss-ecs-a74f:~# cd gitcode
root@hcss-ecs-a74f:~/gitcode# ls
file1 file2 file3 file4 file5 ReadMe
root@hcss-ecs-a74f:~/gitcode# vim ReadMe
root@hcss-ecs-a74f:~/gitcode# git add ReadMe
root@hcss-ecs-a74f:~/gitcode# git commit -m "modify ReadMe:xxx code"
[master bafc141] modify ReadMe:xxx code1 file changed, 1 insertion(+)
root@hcss-ecs-a74f:~/gitcode# git reset --hard HEAD^
HEAD is now at 7e968e9 add file5
root@hcss-ecs-a74f:~/gitcode# git status
On branch master
nothing to commit, working tree clean
root@hcss-ecs-a74f:~/gitcode# cat ReadMe
hello git