admin管理员组文章数量:1650765
目录
- 为什么要有feture分支
- 实践
- 总结
为什么要有feture分支
软件开发中,总有无穷无尽的新的功能要不断添加进来。
添加一个新功能时,你肯定不希望因为一些实验性质的代码,把主分支搞乱了,所以,每添加一个新功能,最好新建一个feature分支,在上面开发,完成后,合并,最后,删除该feature分支。
实践
现在,你接到了一个新任务
于是准备开发
$ git checkout -b newTask
M readme.txt
Switched to a new branch 'newTask'
后来开发完成
$ vim code
$ git add code
$ git status
On branch newTask
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: code
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: readme.txt
$ git commit -m "code of the new task"
[newTask 6af064b] code of the new task
1 file changed, 1 insertion(+)
create mode 100644 code
切回dev
,准备合并
git checkout dev
一切顺利的话,feature分支和bug分支是类似的,合并,然后删除。
但是,此时遇到问题,项目黄了。资料要销毁
$ git branch -d newTask
error: The branch 'newTask' is not fully merged.
If you are sure you want to delete it, run 'git branch -D newTask'.
销毁失败。Git友情提醒,newTask
分支还没有被合并,如果删除,将丢失掉修改,如果要强行删除,需要使用大写的-D
参数。。
我们继续删除
$ git branch -D newTask
Deleted branch newTask (was 6af064b).
总结
开发一个新feature,最好新建一个分支;
如果要丢弃一个没有被合并过的分支,可以通过git branch -D 强行删除。
版权声明:本文标题:git完全教程:015—Git中的Feature分支 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1729532490a1204985.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论