zoukankan      html  css  js  c++  java
  • Git 开发新的功能分支

    软件开发中,总有无穷无尽的新的功能要不断的添加进来。添加一个新功能时,你肯定不希望因为一些实验性质的代码把主分支搞乱了,

    所以每添加一个新功能,最好新建一个feature分支,在上面开发,完成后,合并,最后,删除该feature分支。

    现在你接到一个新的任务:开发代号为Faster的新功能,于是准备开发:

    LV@LV-PC MINGW32 /c/gitskill (dev)
    $ git checkout -b feature-faster
    A hello.txt
    M readme.txt
    Switched to a new branch 'feature-faster'

    LV@LV-PC MINGW32 /c/gitskill (feature-faster)
    $ ls
    hello.txt README.md readme.txt

    LV@LV-PC MINGW32 /c/gitskill (feature-faster)
    $ vim faster.txt


    LV@LV-PC MINGW32 /c/gitskill (feature-faster)
    $ git add faster.txt
    warning: LF will be replaced by CRLF in faster.txt.
    The file will have its original line endings in your working directory.

    LV@LV-PC MINGW32 /c/gitskill (feature-faster)
    $ git commit -m "faster branch commit"
    [feature-faster d84bbe4] faster branch commit
    warning: LF will be replaced by CRLF in faster.txt.
    The file will have its original line endings in your working directory.
    2 files changed, 2 insertions(+)
    create mode 100644 faster.txt
    create mode 100644 hello.txt

    切回dev准备合并分支,一切顺利的话,feature分支和bug分支是类似的,合并,然后删除。

    但是,就在此时,接到上级的命令,因为经费不足,新功能必须取消,

    虽然白干了,但是这个分支还是必须得就地销毁:

    LV@LV-PC MINGW32 /c/gitskill (dev)
    $ git branch -d feature-faster
    error: The branch 'feature-faster' is not fully merged.
    If you are sure you want to delete it, run 'git branch -D feature-faster'.

    没有合并前,不能删除。如果要强制删除需要使用git branch -D feature-faster命令。

    LV@LV-PC MINGW32 /c/gitskill (dev)
    $ git branch -D feature-faster
    Deleted branch feature-faster (was d84bbe4).

    小结:如果要开发新的功能,最好新建一个分支;

    如果要丢弃一个没有被合并过的分支,可以通过git branch -D feature-faster来强行删除

  • 相关阅读:
    [数学-构造矩阵]NEFU 1113
    设计模式【1】:原型模式【创建对象】
    XML(五)dom4j增删改查
    小规则让你写出美丽又高效的程序
    jQuery源代码解析(3)—— ready载入、queue队列
    cocos2d-Lua02Lua面向对象
    在Linux下用make指令编译进度条程序。
    JS两日期相减
    java debugger
    tomcat server.xml
  • 原文地址:https://www.cnblogs.com/LvLoveYuForever/p/5524771.html
Copyright © 2011-2022 走看看