git版本管理系列(十)

git版本管理系列(九)

 分支管理

我們合併分支是一般是用的Fast forward模式,但這種模式下,刪除分支後,會丟掉分支信息。

強制禁用Fast forward模式,Git就會在merge時生成一個新的commit,就可以分支歷史上就可以看出分支信息。

$ git checkout -b dev
$ git add readme.md
$ git commit -m'branch ctrl'

然後切換回master分支

$ git checkout master
$ git merge --no-ff -m "merge with no-ff" dev

合併會創建一個新的commit,所以加上-m參數,把commit描述寫進去。然後查看分支歷史

$ git log --graph --pretty=oneline --abbrev-commit

 bug分支

是指當前任務未完成,要切換到其他分支去修改bug,當前的工作不能提交,所以要保存當前的工作場景,再去切換分支

加入說分支f1出問題了,首先使用git stash保存現在的master分支現場

nelsen-mac:learngit mac$ git stash
Saved working directory and index state WIP on master: 4bdd120 now is ok

然後切換到f1分支去修改

nelsen-mac:learngit mac$ git checkout f1
Switched to branch 'f1'

nelsen-mac:learngit mac$ git checkout -b issue-200   //在f1分支上創建分支,修改完再合併

修復readme.md文件,然後提交

nelsen-mac:learngit mac$ git add readme.md 
nelsen-mac:learngit mac$ git commit -m'issue-200 is ok'
[issue-200 e43e2da] issue-200 is ok
 1 file changed, 2 insertions(+), 1 deletion(-)

切換到f1分支,合併修復的issue-200分支的修改

nelsen-mac:learngit mac$ git checkout f1
Switched to branch 'f1'
nelsen-mac:learngit mac$ git merge --no-ff issue-200
Updating 7d319ad..e43e2da
Fast-forward
 readme.md | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

然後,我們再回去master分支繼續開發

nelsen-mac:learngit mac$ git checkout master
nelsen-mac:learngit mac$ git stash list
stash@{0}: WIP on master: 4bdd120 now is ok

 然後使用 git stash apply stash@{0},回到之前的工作場景

另一種方式是git stash pop,恢復的同時把stash內容也刪了

git stash list 查看保存的所有場景

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章