Git特性多分支开发实战技巧

接手项目时,会涉及多个API或功能点,鉴于开发存在阻塞情况,本文主要介绍如何利用git rebase进行多分支开发

1 拉取远程master分支到本地

# 分支名为master
git clone master.git

2 切出多个特性分支

# 例如三个特性分支feature1、feature2、feature3, 且在主分支下切除三个分支
git branch feature1
git branch feature2
git branch feature3

3 切到某个特性分支进行开发

# 切到特性分支1
git checkout feature1

# 进行开发

# 保存修改
git add xxx

# 创建commit1
git commit -m "feature1-commit1"

# git push
git push -u origin master
# 若采用gerrir代码review工具
git push review HEAD:/refs/for/master

4 在此特性分支进行持续开发

# 保存修改
git add xxx

# 创建commit2
git commit -m "feature1-commit2"

# git push
git push -u origin master
# 若采用gerrir代码review工具
git push review HEAD:/refs/for/master

5 修改此特性分支的多个commit

# 比如feature1上有三个commit, 现在要修改commit1
git rebase -i HEAD~3

# 修改commit文件
pick commit-msg-xxx1
pick commit-msg-xxx2
pick commit-msg-xxx3
XXXXXXXXXXXX

# 如果修改commit1则如下后wq保存退出
edit commit-msg-xxx1
pick commit-msg-xxx2
pick commit-msg-xxx3
XXXXXXXXXXXX

# 如果需要将commit1的修改直接覆盖commit2和commit3,则同时修改commit2和commit3后wq保存退出
edit commit-msg-xxx1
edit commit-msg-xxx2
edit commit-msg-xxx3
XXXXXXXXXXXX

# 然后rebase --continue
git rebase --continue

# 若edit commit2,则停留在commit2了
# 如果修改commit2,则修改后
git add .
git commit --amend --no-e
git rebase --continue

# 若edit commit3,则停留在commit3了
# 如果修改commit3,则修改后
git add .
git commit --amend --no-e
git rebase --continue

# 最后推送到远端
git push
# 若采用gerrir代码review工具
git push review HEAD:/refs/for/master
  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

「已注销」

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值