git-flow工具之命令行操作教程(二)
发表于 2016-09-06
更新于 2024-05-23
分类于 技术专栏
阅读量 1598
字数统计 7915
上一篇我们讲到如何开始版本的开发,接下去讲如何版本发布以及如何热修复。
2.3.2、发布版本:
root@linguang-VirtualBox:/home/nodejsTest/testForGitFlow# git pull origin develop
root@linguang-VirtualBox:/home/nodejsTest/testForGitFlow# git flow release finish -F -p release_v0.0.1
Branches 'release/release_v0.0.1' and 'origin/release/release_v0.0.1' have diverged.
And local branch 'release/release_v0.0.1' is ahead of 'origin/release/release_v0.0.1'.
Branches 'develop' and 'origin/develop' have diverged.
And local branch 'develop' is ahead of 'origin/develop'.
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
Merge made by the 'recursive' strategy.
README.md | 5 +++++
1 file changed, 5 insertions(+)
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
README.md | 2 ++
1 file changed, 2 insertions(+)
Username for 'https://github.com': linxiaowu66
Password for 'https://linxiaowu66@github.com':
To https://github.com/linxiaowu66/testForGitFlow.git
- [deleted] release/release_v0.0.1
Deleted branch release/release_v0.0.1 (was 5440b52).
Username for 'https://github.com': linxiaowu66
Password for 'https://linxiaowu66@github.com':
Counting objects: 15, done.
Compressing objects: 100% (15/15), done.
Writing objects: 100% (15/15), 1.65 KiB | 0 bytes/s, done.
Total 15 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), done.
To https://github.com/linxiaowu66/testForGitFlow.git
4d39bfb..7685e5c develop -> develop
Username for 'https://github.com': linxiaowu66
Password for 'https://linxiaowu66@github.com':
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/linxiaowu66/testForGitFlow.git
4d39bfb..6d5f3ae master -> master
Username for 'https://github.com': linxiaowu66
Password for 'https://linxiaowu66@github.com':
Counting objects: 1, done.
Writing objects: 100% (1/1), 162 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/linxiaowu66/testForGitFlow.git
* [new tag] release_v0.0.1 -> release_v0.0.1
Summary of actions:
- Latest objects have been fetched from 'origin'
- Release branch 'release/release_v0.0.1' has been merged into 'master'
- The release was tagged 'release_v0.0.1'
- Release tag 'release_v0.0.1' has been back-merged into 'develop'
- Release branch 'release/release_v0.0.1' has been locally deleted; it has been remotely deleted from 'origin'
- 'develop', 'master' and tags have been pushed to 'origin'
- You are now on branch 'develop'
中间将会弹出3个编辑框:
- Merge release分支到master分支的日志信息,可以不用填写,也可以协商自己的log;
- 打tag,这个是必填,因为你需要写上你打的tag的名称;
- merge 到develop分支需要填写的log信息。
注意最后的命令git flow release finish -F -p release_v0.0.1
执行的操作比较多,大致可以概括如下:
- 从origin获取最新代码
- 合并Release分支代码到master,这时便弹出第一个编辑框
- 打上tag'release_v0.0.1',这时弹出第二个编辑框
- 合并代码到develop分支上
- 删除本地的Release分支;并将远程对应的分支也删除掉
- push master和develop和tags到远端服务器
- 切换到develop分支
其中-F
和-p
或者其他参数的命令含义是:
参数 | 说明 |
---|---|
-F | 执行操作前先执行fetch |
-s | 对新建的tag签名 |
-u | 签名使用的GPG-key |
-m | 使用指定的注释作为tag的注释 |
-p | 当操作结束后,push到远程仓库中 |
-k | 保留分支 |
-n | 不创建tag |
对于到分支图以及github如图:
这样就ok了!
2.4、hotfix分支的开发
接下去讲一下hotfix,流程几乎和release类似:
root@linguang-VirtualBox:/home/nodejsTest/testForGitFlow# git flow hotfix start fix-bug-001
Switched to a new branch 'hotfix/fix-bug-001'
Summary of actions:
- A new branch 'hotfix/fix-bug-001' was created, based on 'master'
- You are now on branch 'hotfix/fix-bug-001'
Follow-up actions:
- Start committing your hot fixes
- Bump the version number now!
- When done, run:
git flow hotfix finish 'fix-bug-001'
如图:
接着你就开始修复某一个bug,修复完成之后就需要将该bug的修复代码合并到master和develop:
root@linguang-VirtualBox:/home/nodejsTest/testForGitFlow# git pull origin develop
root@linguang-VirtualBox:/home/nodejsTest/testForGitFlow# git flow hotfix finish -F -p fix-bug-001
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
Merge made by the 'recursive' strategy.
README.md | 1 +
1 file changed, 1 insertion(+)
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
README.md | 1 +
1 file changed, 1 insertion(+)
Deleted branch hotfix/fix-bug-002 (was 8ac2377).
Username for 'https://github.com': linxiaowu66
Password for 'https://linxiaowu66@github.com':
Counting objects: 5, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 611 bytes | 0 bytes/s, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 1 local objects.
To https://github.com/linxiaowu66/testForGitFlow.git
39ad5bf..866975c develop -> develop
Username for 'https://github.com': linxiaowu66
Password for 'https://linxiaowu66@github.com':
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/linxiaowu66/testForGitFlow.git
8d2143c..e7976e3 master -> master
Username for 'https://github.com': linxiaowu66
Password for 'https://linxiaowu66@github.com':
Counting objects: 1, done.
Writing objects: 100% (1/1), 163 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/linxiaowu66/testForGitFlow.git
* [new tag] fix-bug-002 -> fix-bug-002
Summary of actions:
- Latest objects have been fetched from 'origin'
- Hotfix branch 'hotfix/fix-bug-002' has been merged into 'master'
- The hotfix was tagged 'fix-bug-002'
- Hotfix tag 'fix-bug-002' has been back-merged into 'develop'
- Hotfix branch 'hotfix/fix-bug-002' has been locally deleted
- 'develop', 'master' and tags have been pushed to 'origin'
- You are now on branch 'develop'
如果你忘记了刚才加了-F -p的参数,那么就需要你手工push到remote上去:
root@linguang-VirtualBox:/home/nodejsTest/testForGitFlow# git push origin develop
Username for 'https://github.com': linxiaowu66
Password for 'https://linxiaowu66@github.com':
Counting objects: 5, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 610 bytes | 0 bytes/s, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 1 local objects.
To https://github.com/linxiaowu66/testForGitFlow.git
7685e5c..39ad5bf develop -> develop
root@linguang-VirtualBox:/home/nodejsTest/testForGitFlow# git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
root@linguang-VirtualBox:/home/nodejsTest/testForGitFlow# git push origin master
Username for 'https://github.com': linxiaowu66
Password for 'https://linxiaowu66@github.com':
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/linxiaowu66/testForGitFlow.git
6d5f3ae..8d2143c master -> master
root@linguang-VirtualBox:/home/nodejsTest/testForGitFlow#
root@linguang-VirtualBox:/home/nodejsTest/testForGitFlow#
root@linguang-VirtualBox:/home/nodejsTest/testForGitFlow# git push --tags
Username for 'https://github.com': linxiaowu66
Password for 'https://linxiaowu66@github.com':
Counting objects: 1, done.
Writing objects: 100% (1/1), 161 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/linxiaowu66/testForGitFlow.git
* [new tag] fix-bug-001 -> fix-bug-001
发布完这个hotfix分支之后整个代码提交历史图如下:
这么演练一番应该可以上手项目了吧?如果命令操作起来依然费劲或者记不住的话,那就使用UI操作吧:SourceTree
![](https://blogimage.5udou.cn/douBiPicture/douBi5.jpg)
参考:
公众号关注一波~
![微信公众号](https://blogimage.5udou.cn/homePage/%E5%85%AC%E4%BC%97%E5%8F%B7-%E7%99%BD%E8%89%B2%E7%89%88.png?x-oss-process=style/addWaterMarkBottom)
网站源码:linxiaowu66 · 豆米的博客
Follow:linxiaowu66 · Github
关于评论和留言
如果对本文 git-flow工具之命令行操作教程(二) 的内容有疑问,请在下面的评论系统中留言,谢谢。