Git:如何挤压分支上的所有提交 [英] Git: How to squash all commits on branch

查看:118
本文介绍了Git:如何挤压分支上的所有提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 master 来创建新分支:

git checkout -b testbranch

现在我想挤压那些20次提交。我是这样做的:



git rebase -i HEAD〜20



如果我不知道有多少次提交,那么呢?有没有办法做到这一点:



git rebase -i这个分支上的所有内容

解决方案

另一种压缩所有提交的方法是将索引重置为master:

<$ p $ g $ git checkout yourBranch
git reset $(git merge-base master yourBranch)
git add -A
git commit -m在你的分支上提交一个

这并不完美,因为这意味着您知道yourBranch来自哪个分支。 >
注意:发现原始分支不是容易/可能使用Git 视觉方式往往是最简单的,因为在这里看到)。

I make new branch from master with:

git checkout -b testbranch

I make 20 commits into it.

Now I want to squash those 20 commits. I do that with:

git rebase -i HEAD~20

What about if I don't know how many commits? Is there any way to do something like:

git rebase -i all on this branch

解决方案

Another way to squash all your commits is to reset the index to master:

 git checkout yourBranch
 git reset $(git merge-base master yourBranch)
 git add -A
 git commit -m "one commit on yourBranch"

This isn't perfect as it implies you know from which branch "yourBranch" is coming from.
Note: finding that origin branch isn't easy/possible with Git (the visual way is often the easiest, as seen here).

这篇关于Git:如何挤压分支上的所有提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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