我们分两部分讲解,一部分讲解提交记录的压缩,一部分讲解分支之间的变基操作。
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 图形示例