gitflow学习总结

Installing git-flow

需要先安装git-flow软件后,才可使用。

  • Mac OS: brew install git-flow
  • Linux: apt-get install git-flow
  • Windows: 使用Git for Windows软件,该软件包含了Git-flow

详见官方安装教程

Use git-flow

就像代码需要代码规范一样,代码管理同样需要一个清晰的流程和规范。

Vincent Driessen 同学为了解决这个问题提出了A Successful Git Branching Model

Git Flow流程图:

Git flow

Init git-flow

在使用git-flow前,需要先在仓库中执行init命令。

$ git flow init
Initialized empty Git repository in ~/project/.git/
No branches exist yet. Base branches must be created now.
Branch name for production releases: [master]
Branch name for "next release" development: [develop]

How to name your supporting branch prefixes?
Feature branches? [feature/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []

开发新特性

git flow feature start [特性名称]

开始一个新的模块开发,此命令基于develop分创建一个名为[模块名称]的新本地分支并切换到此分支。

DEMO:

$ git flow feature start leapx1.2.1
Switched to a new branch 'feature/leapx1.2.1'

Summary of actions:
- A new branch 'feature/leapx1.2.1' was created, based on 'develop'
- You are now on branch 'feature/leapx1.2.1'

Now, start committing on your feature. When done, use:

     git flow feature finish leapx1.2.1

新特性开发完成

git flow feature finish [特性名称]

协作开发新特性

当需要协作开发时,可以将新特性分支推送到远程仓库:

git flow feature publish [特性名称]

其他开发人员即可通过如下命令获取新特性(2.0后将只能使用此命令):

git flow feature track [特性名称]

也可以使用(已申明废弃)

git flow feature pull origin [特性名称]    # 已申明废弃,需使用下面命令

pull远程特性分支的变更。

发布新版本

git flow release start [RELEASE] [BASE]

RELEASE:版本名称

BASE:develop分支下的commit的sha-1值。

命令仅基于develop分支创建本地release分支,将此分支推送到远程仓库:

git flow release publish [RELEASE]

使用

git flow release track [RELEASE]

pull远程release分支的变更。

完成新版本

git flow release finish [RELEASE]

合并release分支到master分支,用release分支名打tag;合并release分支到develop分支;删除release分支。

DEMO:

$ git flow release finish leapx1.2.1
Branches 'master' and 'origin/master' have diverged.
Fatal: And branch 'master' may be fast-forwarded.

紧急修复

发现某个提交有bug,使用

git flow hotfix start [VERSION] [BASENAME]

VERSION:修正版本名称

BASENAME: release分支名

从master新开一个分支,分支名称为VERSION参数名。

完成修复

git flow hotfix finish [VERSION]

完成修复。修复分支合并到master,develop,master分支打上修正版本tag。

提交Tag

完成release分支或者完成hotfix分支时,需要输入tag标签,然后自动合并到master分支上。需要在master分支上向git仓库推送标签。

git push --tags

统计某个人时间范围的提交代码

git log --author="luyanliang" --since='2021-12-01' --until='2021-12-31' --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 + $2 } END { printf "增加的行数:%s 删除的行数:%s 总行数: %s\n",add,subs,loc }'

参考资料

原文地址:https://www.cnblogs.com/luyanliang/p/15760339.html