本文介绍了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 ).

See commit 1d14d0c (24 May 2019) by Vishal Verma (reloadbrain).

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."));


  • git rebase --interactive
  • 在新的基础上重播部分或全部提交,从而使您能够进行压缩(或更近些的修复",请参见此),直接转到:

    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
    

    如果您选择压缩所有 tmp 的提交(但与 merge --squash 相反,则可以选择重播某些内容,并压缩其他内容).

    If you choose to squash all commits of tmp (but, contrary to merge --squash, you can choose to replay some, and squashing others).

    所以区别是:

    • squash 不会触摸您的源分支(此处为 tmp ),并在您需要的位置创建一个提交.
    • rebase 允许您使用以下命令继续使用同一源分支(仍为 tmp ):
      • 新基地
      • 更清洁的历史
      • squash 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

        这篇关于merge --squash和rebase有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-04 19:20