merge --squash和rebase有什么区别? [英] What is the difference between merge --squash and rebase?

查看:93
本文介绍了merge --squash和rebase有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是git的新手,我想了解南瓜和变基之间的区别.据我了解,您在重新设置基准时会执行壁球操作.

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.

推荐答案

git merge --squash git rebase --interactive 都可以产生压缩"提交.
但是它们有不同的用途.

Both git merge --squash and git rebase --interactive can produce a "squashed" commit.
But they serve different purposes.

将在目标分支上产生压缩的提交,而不会标记任何合并关系.
(注意:它不会立即产生提交:您需要一个附加的 git commit -m"squash branch" )
如果您想完全丢弃源分支,这很有用,请从(模式取自这样的问题):

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

收件人:

git merge --squash tmp
git commit -m "squash tmp"

      X-------------------G stable
     /                   
a---b---c---d---e---f---g tmp

,然后删除 tmp 分支.

注意: git merge 具有-commit 选项,但不能与-squash 一起使用.不能同时使用-commit -squash .
自Git 2.22.1(2019年第三季度)以来,这种不兼容被明确指出:

Note: git merge has a --commit option, but it cannot be used with --squash. It was never possible to use --commit and --squash together.
Since Git 2.22.1 (Q3 2019), this incompatibility is made explicit:

参见提交1d14d0c (2019年5月24日)://github.com/reloadbrain"rel =" noreferrer> Vishal Verma( reloadbrain ).
(由 Junio C Hamano合并- gitster -提交33f2790 ,2019年7月25日)

See commit 1d14d0c (24 May 2019) by Vishal Verma (reloadbrain).
(Merged by Junio C Hamano -- gitster -- in commit 33f2790, 25 Jul 2019)

合并:拒绝-commit -squash

以前,当提供-squash 时," option_commit "处于静默状态掉了.对于试图覆盖的用户来说,这可能是令人惊讶的

merge: refuse --commit with --squash

Previously, when --squash was supplied, 'option_commit' was silently dropped. This could have been surprising to a user who tried to override the no-commit behavior of squash using --commit explicitly.

git/git builtin/merge.c#cmd_merge() 现在包括:

git/git builtin/merge.c#cmd_merge() now includes:

if (option_commit > 0)
    die(_("You cannot combine --squash with --commit."));


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