1.分支

1.1查看分支列表

$ git branch
* master

1.2创建并切换到新的分支

$ git checkout -b chency
Switched to a new branch 'chency'

$ git branch
* chency
  master

1.3切换分支

$ git checkout master
Switched to branch 'master'

1.4合并分支

$ git merge chency
Already up-to-date.

1.5删除分支

$ git branch -d chency
Deleted branch chency (was 997bff3).

2.rebase

被rebase的分支的历史会被整体迁移到当前分支上。

$ git rebase dev
$ git branch
* (no branch, rebasing master)
  dev
  master
$ git status -s 
UU file1

$ git add file1
$ git rebase --continue

撤销git-rebase

$ git reflog 

列出全部的操作历史

04b2353 HEAD@{0}: rebase finished: returning to refs/heads/master
04b2353 HEAD@{1}: rebase: I
fc8fc32 HEAD@{2}: rebase: checkout dev
97bd1e2 HEAD@{3}: commit: I
34caed3 HEAD@{4}: checkout: moving from dev to master
fc8fc32 HEAD@{5}: commit: one
34caed3 HEAD@{6}: checkout: moving from master to dev
34caed3 HEAD@{7}: checkout: moving from dev to master
34caed3 HEAD@{8}: checkout: moving from master to dev


git reset --hard HEAD@{5}

使用参数--hard 不仅修改仓库的当前修订位置,还会使用此修订的文件覆盖工作区和暂存区的文件。