0%

git 和 git-flow 备忘录

git 和 git-flow 备忘录

> A successful Git branching model by Vincent Driessen

安装 git 和 git-flow-avh

1
2
brew install git
brew install git-flow-avh

初始化项目

使用 git-flow 命令初始化

1
git-flow init

添加初始化文件

1
2
echo "# Hello World" >> README.md
echo ".DS_Store\nThumbs.db" >> .gitignore

发布到远程

1
2
git remote add origin git@github.com:violetqqy/git-flow-demo.git
git push origin --all

特性分支

增加新特性

特性分支基于 develop 分支创建。

1
git-flow feature start [text]

相当于 >>

1
git checkout -b feature/text

给特性分支添加文件并作提交

1
2
3
4
5
6
7
echo "feature text" >> text.txt

git add .
git commit -m "text"
git push origin [feature/text]
...

完成新特性

1
git-flow feature finish [text]

相当于 >>

1
2
3
git checkout develop
git merge --no-ff [feature/text]
git branch -d [feature/text]

_日志

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Switched to branch 'develop'
Updating 55b8783..4eb2dc9
Fast-forward
text.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 text.txt
To github.com:violetqqy/git-flow-demo.git
- [deleted] feature/text
Deleted branch feature/text (was 4eb2dc9).

Summary of actions:
- The feature branch 'feature/text' was merged into 'develop'
- Feature branch 'feature/text' has been locally deleted; it has been remotely deleted from 'origin'
- You are now on branch 'develop'

远程发布新特性

1
git-flow feature publish [FEATURENAME]

远程拉取新特性

1
git-flow feature pull origin [FEATURENAME]

预发布分支

开始准备release版本

git flow release start [RELEASENAME] [BASE(提交记录的 sha-1 hash 值)]

1
git flow release start [version0.0.0]

_日志

1
2
3
4
5
6
7
8
9
10
11
12
Switched to a new branch 'release/version0.0.0'

Summary of actions:
- A new branch 'release/version0.0.0' was created, based on 'develop'
- You are now on branch 'release/version0.0.0'

Follow-up actions:
- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:

git flow release finish 'version0.0.0'

本地release分支发布到远程

1
git flow release publish [version0.0.0]

_日志

1
2
3
4
5
6
7
8
9
10
11
Total 0 (delta 0), reused 0 (delta 0)
To github.com:violetqqy/git-flow-demo.git
* [new branch] release/version0.0.0 -> release/version0.0.0
Branch 'release/version0.0.0' set up to track remote branch 'release/version0.0.0' from 'origin'.
Already on 'release/version0.0.0'
Your branch is up to date with 'origin/release/version0.0.0'.

Summary of actions:
- The remote branch 'release/version0.0.0' was created or updated
- The local branch 'release/version0.0.0' was configured to track the remote branch
- You are now on branch 'release/version0.0.0'

你可以通过 git flow release track [RELEASENAME] 命令签出 release 版本的远程变更

完成 release 版本

1
git flow release finish [version0.0.0]
  1. 归并 release 分支到 ‘master’ 分支
  2. 用 release 分支名打 Tag
  3. 归并 release 分支到 ‘develop’
  4. 移除 release 分支
1
2
3
4
5
6
>> Creating Tags
git tag -a [name] -m [description]
>> Sharing Tags
git push origin [tag name]
>> Sharing All Tags
git push origin --tags

紧急修复分支

紧急修复分支是基于 master 上某个 tag 标记的生产版本。

开始一个紧急修复分支

1
git flow hotfix start VERSION [BASENAME(finish release时填写的版本号)]

_日志

1
2
3
4
5
6
7
8
9
10
11
12
Switched to a new branch 'hotfix/version0.0.0'

Summary of actions:
- A new branch 'hotfix/version0.0.0' was created, based on 'master'
- You are now on branch 'hotfix/version0.0.0'

Follow-up actions:
- Start committing your hot fixes
- Bump the version number now!
- When done, run:

git flow hotfix finish 'version0.0.0'
1
git tag -a v0.0.1 -m "hotfix v0.0.0"

参考资料

项目地址