Git是一个分布式版本控制系统,它会保存文件修改的历史版本,可以使用下面的命令回退文件到某个历史版本:
git checkout :把整个git仓库文件回退到 commit 参数指定的版本
git checkout [] [--] :回退 filepath 文件为 commit 参数指定的版本
git reset :把git的HEAD指针指向到 commit 对应的版本,本地文件内容不会被回退
git reset --hard :把git的HEAD指针指向到 commit 对应的版本,本地文件内容也会被回退
git checkout
git checkout 命令把整个git仓库文件回退到 commit 参数指定的版本,该参数值可以是具体的commit hash值,也可以通过HEAD index来指定。例如,HEAD^ 对应最新版本的上一个版本,那么 git checkout HEAD^ 命令回退git仓库下的文件内容到上一个版本,同时从当前分支脱离,处在一个未命名分支下面:
$ git checkout HEAD^
Note: checking out 'HEAD^'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to cre