问题描述
我是git的新手,我想了解一个壁球和rebase之间的区别。正如我所理解的那样,你在进行rebase时执行了一个压扁。
这两个 git merge --squash 和 git rebase --interactive 可以产生一个压扁的提交。
但它们有不同的用途。
-
会产生一个压扁的提交目标分支,不标记任何合并关系。
(注意:它不会立即产生提交:您需要额外的 git commit -msquash branch)
如果你想完全抛弃源代码分支,从(
在一个新的基础上重放你的一些或全部提交,允许你压扁(或者更近一步修复,见),直接进入:
git checkout tmp
git rebase -i stable
stable
X ------------------- G tmp
/
a --- b
如果您选择压扁所有提交s tmp (但是,与 merge --squash 相反,您可以选择重播一些内容,并压缩其他内容) 。
所以区别在于:
$ b $ ul
- 新基地
- 清洁器历史记录
I'm new to git and I'm trying to understand the difference between a squash and a rebase. As I understand it you perform a squash when doing a rebase.
Both git merge --squash and git rebase --interactive can produce a "squashed" commit.
But they serve different purposes.
will produce a squashed commit on the destination branch, without marking any merge relationship.
(Note: it does not produce a commit right away: you need an additional git commit -m "squash branch")
This is useful if you want to throw away the source branch completely, going from (schema taken from SO question):
git checkout stable X stable / a---b---c---d---e---f---g tmp
to:
git merge --squash tmp git commit -m "squash tmp" X-------------------G stable / a---b---c---d---e---f---g tmp
and then deleting tmp branch.
replays some or all of your commits on a new base, allowing you to squash (or more recently "fix up", see this SO question), going directly to:
git checkout tmp git rebase -i stable stable X-------------------G tmp / a---b
If you choose to squash all commits of tmp (but, contrary to merge --squash, you can choose to replay some, and squashing others).
So the differences are:
- merge does not touch your source branch (tmp here) and creates a single commit where you want.
- rebase allows you to go on on the same source branch (still tmp) with:
- a new base
- a cleaner history
这篇关于在git中,合并--squash和rebase有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!