Git study Day02 分支

陳重陽發表於2017-01-14

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 不僅修改倉庫的當前修訂位置,還會使用此修訂的檔案覆蓋工作區和暫存區的檔案。