2016年8月17日 星期三

[學習] Git (08) 分支branch

http://ithelp.ithome.com.tw/articles/10135016

先學到一個概念,從當前分支再去建立分支,兩個分支會走在同一條線,如果這時候在建立的分支上有做到修改,那你就不能使用git branch -d [branch_name]去刪除掉該分支,系統會有error要你先做merge。
舉例:
error: The branch 'newbranch2' is not fully merged.
If you are sure you want to delete it, run 'git branch -D newbranch2'.

那是不是merge以後,就會變成同一條線只剩一個分支,不知道。
A: YES (8/27)

如果是先用git log找到分支的上一版本id,然後用git checkout 上一版本id,那就會切換到該版本,然後再用git checkout -b [branch-name],這時候就會切換到建立出來的新分支,並且此新分支就會跟原來分支分開在不同的路線。


指令:
git branch    顯示所有分支
git branch [branch_name]       建立新分支
git checkout -b [branch_name]      建立新分支並且切換過去,建議作法
git checkout [branch_name]    切換到該分支
git branch -d [branch_name]    刪除該分支
git branch -D [branch_name]   刪除掉(同條線)尚未merge的分支
git log            查看分支的版本紀錄

沒有留言:

張貼留言