git合并多个提交(在as里)

前言

很多人建议rebase ,网上的

但是我使用gerrit ,似乎不支持, 不建议 在这环境下 rebase

所以, 阐述一种reset + cherry pick 的方式

背景

我在本地开了一个f分支, 进行了10 次commit (假设第前11 次是 327753 这个提交)

现在我要把这个10 commit 放到 master 分支上,

我首先要 合并10 为 1 个, 因为gerrit 希望的每次提交到服务器的 patch 是等于本地的一个commit

merge commit

我如何合并commit

git reset 327753 // 回到master 的分叉点

git status // 因为 reset 默认是 使用了mix 模式,所以你此时看到自己10commit 的modified 在 git st 中的stage area

扫描二维码关注公众号,回复: 10002349 查看本文章

git ci -m “reset and combine 10 commint into 1 commit” // 此时, 你的10 commit --》 1 commit

(注意,你还在f 分支上)

merge branch

我现在要将f 分支的 10 转1 的commit 合并到 master

我使用 cherry pick

直接在AS 里,切换到 master 的分支,然后, 在master 的分支上,进行对 f 分支的 cherry pick

和 master 最近其他同事的提交没有冲突,那么顺利 cherry pick, 写上 commit msg 就可以啦。。

发布了216 篇原创文章 · 获赞 33 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/paulkg12/article/details/94138946