git快速入门(3)

3.7分支管理

分支管理就是业务可以在多个分支上进行。

alt

分支管理的好处有:

  • 不同的功能的代码可以在不同的分支上进行,避免各个分支的代码混在一起,并行进行各个功能,推进项目进度。
  • 降低试错成本,对于一些新功能的实现,可以在非主分支上进行,完成开发后再增加到主分支,如果开发失败可以直接删除该分支,而不会影响到主分支。

查看当前所有分支。

$ git branch -v
* master 34615c1 add deletedtest.txt

新建一个分支。

$ git status
On branch master
nothing to commit, working tree clean

24724@LAPTOP-OCSC7S98 MINGW64 /e/gitworkspace/gitviedo/wechat (master)
$ git branch hot_fix

24724@LAPTOP-OCSC7S98 MINGW64 /e/gitworkspace/gitviedo/wechat (master)
$ git branch -v
  hot_fix ed1955a test
* master  ed1955a test

切换分支。

24724@LAPTOP-OCSC7S98 MINGW64 /e/gitworkspace/gitviedo/wechat (master)
$ git checkout hot_fix
Switched to branch 'hot_fix'

合并分支。下面再hot_fix上做一个修改,并将其合并到master分支。

24724@LAPTOP-OCSC7S98 MINGW64 /e/gitworkspace/gitviedo/wechat (hot_fix)
$ vim demo01

24724@LAPTOP-OCSC7S98 MINGW64 /e/gitworkspace/gitviedo/wechat (hot_fix)
$ git add .
warning: LF will be replaced by CRLF in demo01.
The file will have its original line endings in your working directory.

24724@LAPTOP-OCSC7S98 MINGW64 /e/gitworkspace/gitviedo/wechat (hot_fix)
$ git commit .
warning: LF will be replaced by CRLF in demo01.
The file will have its original line endings in your working directory.
[hot_fix 07a3656] hot_fix
 1 file changed, 1 insertion(+)

24724@LAPTOP-OCSC7S98 MINGW64 /e/gitworkspace/gitviedo/wechat (hot_fix)
$ git branch -v
* hot_fix 07a3656 hot_fix
  master  ed1955a test

24724@LAPTOP-OCSC7S98 MINGW64 /e/gitworkspace/gitviedo/wechat (hot_fix)
$ git checkout master
Switched to branch 'master'

24724@LAPTOP-OCSC7S98 MINGW64 /e/gitworkspace/gitviedo/wechat (master)
$ git merge hot_fix
Updating ed1955a..07a3656
Fast-forward
 demo01 | 1 +
 1 file changed, 1 insertion(+)

24724@LAPTOP-OCSC7S98 MINGW64 /e/gitworkspace/gitviedo/wechat (master)
$ git branch -v
  hot_fix 07a3656 hot_fix
* master  07a3656 hot_fix