GitLab-合併多个commit

在使用Git作为版控时,会提交许多大大小小的commit,而把这些commit拼凑起来才会是一个完整的任务,为了避免太多的commit造成版控的混乱,就会将这些commit给压缩成一个完整的名称。

查询log
$ git log
有两种方法可用来选择需要合併的commit

方法一、此步骤是指此从HEAD开始数来到第三个commit,包含自身。

$ git rebase -i HEAD~3

方法二、此步骤是指此版本号之前的commit,不包含自身。

$ git rebase -i 版本号
执行rebase命令后会看到所要合併的commit
pick    6cdfbc0    '注释**********'pick    793ee97    '注释*********'pick    879e453    '注释**********'
从第二个开始把pick改成squashs然后储存关闭编辑。
pick    6cdfbc0    '注释**********'s       793ee97    '注释*********'s       879e453    '注释**********'
没有任何冲突的话会出现以下窗口编辑,可重新编辑commit完后储存关闭编辑。
This is a combination of 4 commits.  #The first commit’s message is:  注释...... The 2nd commit’s message is:  注释...... The 3rd commit’s message is:  注释...... Please enter the commit message for your changes. Lines starting # with ‘#’ will be ignored, and an empty message aborts the commit.
再次查询log,就会发现已把上述commit给合併完成。

ps. 放弃此次commit压缩

$ git rebase --abort

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章