# 恢复暂存区的指定文件到工作区
$ git checkout [file]
# 恢复某个commit的指定文件到暂存区和工作区
$ git checkout [commit] [file]
# 恢复暂存区的所有文件到工作区
$ git checkout .
# 重置暂存区的指定文件,与上一次commit保持一致,但工作区不变
$ git reset [file]
# 修改头指针,暂存区数据消失,工作空间的数据恢复到以前状态
$ git reset --hard
# 仅仅修改头指针,暂存区以及工作空间中的所有东西都不会改变
$ git reset --soft
# 修改头指针,并且暂存区中的内容会丢失,工作空间中的数据不会改变
$ git reset --mixed
# 重置当前分支的指针为指定commit,同时重置暂存区,但工作区不变
$ git reset [commit]
# 重置当前分支的HEAD为指定commit,同时重置暂存区和工作区,与指定commit一致
$ git reset --hard [commit]
# 迭代到上一个版本
$ git reset --hard HEAD ^
# 回滚到前三个版本
$ git reset --hard HEAD~3
# 重置当前HEAD为指定commit,但保持暂存区和工作区不变
$ git reset --keep [commit]
# 新建一个commit,用来撤销指定commit
# 后者的所有变化都将被前者抵消,并且应用到当前分支
$ git revert [commit]
# 保存当前工作切换分支,注意stash是以栈的方式保存的,先进后出。
$ git stash
$ git stash pop # 会将list保存的列表也给删除掉
$ git stash apply # 不会删除列表里的内容会默认恢复第一个,如果想恢复指定内容可以使用git stash apply list名称
$ git stash drop list # 名称可以移除指定list
$ git stash clear # 移除所有lsit
$ git stash show # 查看栈中最新保存的stash和当前目录的差异。