Git:如何挤压分支上的所有提交 [英] Git: How to squash all commits on branch
问题描述
我使用 master
来创建新分支:
现在我想挤压那些20次提交。我是这样做的: 如果我不知道有多少次提交,那么呢?有没有办法做到这一点: 另一种压缩所有提交的方法是将索引重置为master: git checkout -b testbranch
git rebase -i HEAD〜20
git rebase -i这个分支上的所有内容
<$ 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屋!