Git 開發新的功能分支

來源:互聯網
上載者:User

標籤:

軟體開發中,總有無窮無盡的新的功能要不斷的添加進來。添加一個新功能時,你肯定不希望因為一些實驗性質的代碼把主分支搞亂了,

所以每添加一個新功能,最好建立一個feature分支,在上面開發,完成後,合并,最後,刪除該feature分支。

現在你接到一個新的任務:開發代號為Faster的新功能,於是準備開發:

[email protected] MINGW32 /c/gitskill (dev)
$ git checkout -b feature-faster
A hello.txt
M readme.txt
Switched to a new branch ‘feature-faster‘

[email protected] MINGW32 /c/gitskill (feature-faster)
$ ls
hello.txt README.md readme.txt

[email protected] MINGW32 /c/gitskill (feature-faster)
$ vim faster.txt


[email protected] 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.

[email protected] 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分支是類似的,合并,然後刪除。

但是,就在此時,接到上級的命令,因為經費不足,新功能必須取消,

雖然白乾了,但是這個分支還是必須得就地銷毀:

[email protected] 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命令。

[email protected] MINGW32 /c/gitskill (dev)
$ git branch -D feature-faster
Deleted branch feature-faster (was d84bbe4).

小結:如果要開發新的功能,最好建立一個分支;

如果要丟棄一個沒有被合并過的分支,可以通過git branch -D feature-faster來強行刪除

Git 開發新的功能分支

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.