在执行git checkout之前,如果是切换分支,需先确认分支已创建。
1.当前分支转换到另一分支
$ git checkout <branch>
2.创建新分支并转换到此分支
$ git checkout -b <branch>
此操作等价于
$ git branch <branch>
$ git checkout <branch>
3.丢弃暂存区修改,使本地文件恢复修改前的状态
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: aa
$ git checkout aa //按照提示,丢弃改变使用git checkout <file>
4.基于某分支的某一次commit来创建分支
$ git checkout &