git修复指定tag的bug
一、情景
当前发现V1.0有bug,需要紧急修复。
二、修复案例
1、查看标签对应的commit_id
git tag
git show V1.0
2、版本回滚
- 将主分支回滚到对应commit_id的版本
git reset --hard 11e251
3、新建fix分支
- 不能直接在主分支上进行修改,因为主分支修改push后,后续的版本都会丢失——白干
git checkout -b bugfix
4、主分支回到最新状态
git checkout master
git pull origin master
5、开始修复bug
git checkout bugfix # 切到bugfix分支,再开始修改
# 在这里对bug进行修复
#...........
# 将bugfix分支提交到远程
git add .
git commit -m 'fix V1.0 bug'
git tag V1.0.1
6、(非必须)merge到主分支
- 如果V1.0的功能,在后续开发用使用到,需要合并到主分支
- 如果后续开发不使用,例如1.0和2.0是两个大版本迭代,则不需要merge到主分支
1)如果后续功能涉及到该bug
# 方式一:本地先merge,然后push到远程,这种方式可能会因为主分支受保护无法push
git checkout master # 先切换到主分支
git merge bugfix
# 方式二(建议):先push,再远程merge
git push origin bugfix
git push origin V1.0.1
7、推送tag
1)后续功能涉及该bug
# 本地merge,然后push的方式在这一步进行push
git push origin master
git push origin --tags
2)后续版本不涉及该bug,由于不是在master分支打的tag,所以在Graph中无法看见
git push origin --tags
博客内容仅供参考,部分参考他人优秀博文,仅供学习使用