git rebase简单介绍

我们分两部分讲解,一部分讲解提交记录的压缩,一部分讲解分支之间的变基操作。

1. 提交记录压缩

我们在开发一个需求时,如果提交记录过多,容易造成提交记录混乱,可以通过squash来完成多次提交记录的压缩。

1.1 查询提交记录

git log --pretty=format:"%h %s" --graph

1.2 git rebase

(1)git rebase -i HEAD~3

pick e795586 c-all
pick 4df7da9 c4
pick 7cdf4c6 c5

修改为

pick e795586 c-all
s 4df7da9 c4
s 7cdf4c6 c5

commit msg:

# This is a combination of 3 commits.
# This is the 1st commit message:

c-all

# This is the commit message #2:

c4

# This is the commit message #3:

c5

修改为:

# This is a combination of 3 commits.
# This is the 1st commit message:

c-a

# This is the commit message #2:

# This is the commit message #3:

1.3 查询rebase后的log

* 0391383 c-a
* 853354e Initial commit

2. 分之间变基

2.1 步骤

1. 新建repo,新建文件,本地clone代码

2. 新建分支:git checkout -b feature1,新分支上开发,然后commit

3. main分支开发,并commit

4. 在feature1分支上切换回main分支,并pull最新代码

5. 切回feature1分支,git rebase mian

6. 切到main妇女之,git rebase feature1

2.2 图形示例

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值