在推入Git之前合并多个提交 [英] Combining multiple commits before pushing in Git

查看:149
本文介绍了在推入Git之前合并多个提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地存储库上有一堆提交,它们在主题上相似。我想在推送到远程之前将它们合并为一个提交。我该怎么做?我认为 rebase 可以做到这一点,但我无法理解文档。

解决方案你想要做的是在git中被称为挤压。当你这样做的时候有太多的选择(太多了?),但是如果你只是想把所有的unpushed提交合并成一个单独的提交,请执行以下操作:

 git rebase -i origin / master 

你的文本编辑器( -i 用于interactive)和一个如下所示的文件:

 选择16b5fcc代码,测试未通过
选择c964dea更近距离
挑选06cf8ee有所变动
挑选396b4a3测试通过
挑选9be7fdb更好评论
pick 7dba9cb全部完成

更改所有 pick 压扁(或 s ),除了第一个:

 选择16b5fcc代码,测试未通过
压扁c964dea靠近
压扁06cf8ee改变某些东西
压缩396b4a3测试通过
压缩9be7fdb更好的评论
squash 7dba9cb全部完成

保存文件和前它是你的编辑器。然后另一个文本编辑器将打开,让您将来自所有提交的提交消息合并为一个大提交消息。



瞧! Google搜索git squashing会给你所有其他可用选项的解释。


I have a bunch of commits on my local repository which are thematically similar. I'd like to combine them into a single commit before pushing up to a remote. How do I do it? I think rebase does this, but I can't make sense of the docs.

解决方案

What you want to do is referred to as "squashing" in git. There are lots of options when you're doing this (too many?) but if you just want to merge all of your unpushed commits into a single commit, do this:

git rebase -i origin/master

This will bring up your text editor (-i is for "interactive") with a file that looks like this:

pick 16b5fcc Code in, tests not passing
pick c964dea Getting closer
pick 06cf8ee Something changed
pick 396b4a3 Tests pass
pick 9be7fdb Better comments
pick 7dba9cb All done

Change all the pick to squash (or s) except the first one:

pick 16b5fcc Code in, tests not passing
squash c964dea Getting closer
squash 06cf8ee Something changed
squash 396b4a3 Tests pass
squash 9be7fdb Better comments
squash 7dba9cb All done

Save your file and exit your editor. Then another text editor will open to let you combine the commit messages from all of the commits into one big commit message.

Voila! Googling "git squashing" will give you explanations of all the other options available.

这篇关于在推入Git之前合并多个提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆