代码之家  ›  专栏  ›  技术社区  ›  mkrieger1 djuarezg

在交互式重新设置基础后删除空提交,即使使用了--keep Empty

  •  4
  • mkrieger1 djuarezg  · 技术社区  · 9 年前

    --keep-empty 选择 git rebase ,而我 不确定我是否误解了这个选项的作用,或者是否存在错误。

    下面是一个简单的示例:

    安装程序

    1. $ git init
      $ echo something >base.txt
      $ git add base.txt
      $ git commit -m 'some base commit to not run into the root corner case'
      
    2. 创建一个新的提交,添加两个新文件。

      $ echo A >a.txt; echo B >b.txt
      $ git add a.txt b.txt
      $ git commit -m 'add A and B'
      
    3. 修改其中一个文件。

      $ echo A1 >a.txt
      $ git add a.txt
      $ git commit -m 'change A'
      
    4. 修改另一个文件。

      $ echo B1 >b.txt
      $ git add b.txt
      $ git commit -m 'change B'
      

    $ git checkout -b rebased master
    $ git rebase --keep-empty -i :/base
    

    选择 edit 提交位置 A 和 B 并对其进行更改,以便仅 B A. 保密):

    $ git rm a.txt
    $ git commit --amend
    $ git rebase --continue
    

    A. 现在修改会产生冲突:

    error: could not apply 182aaa1... change A
    
    When you have resolved this problem, run "git rebase --continue".
    If you prefer to skip this patch, run "git rebase --skip" instead.
    To check out the original branch and stop rebasing, run "git rebase --abort".
    Could not apply 182aaa1701ad100fc02a5d5500cacebdd317a24b... change A
    

    a.txt :

    $ git mergetool
    Merging:
    a.txt
    
    Deleted merge conflict for 'a.txt':
      {local}: deleted
      {remote}: modified file
    Use (m)odified or (d)eleted file, or (a)bort? d
    

    提交位置 A.

    $ git diff --cached
    # nothing
    

    并完成再底座:

    $ git rebase --continue
    Successfully rebased and updated refs/heads/rebased.
    

    A. 其中一个。然而,因为我选择了 选项,我仍然希望中存在一个空提交 rebased ,这会告诉我 如果它在那里,就会被修改。

    但显然情况并非如此:

    $ git log --oneline master
    f893569 change B
    182aaa1 change A
    3340b71 add A and B
    38cb5da some base commit to not run into the root corner case
    
    $ git log --oneline rebased
    73a2c05 change B
    55f502b add A and B
    38cb5da some base commit to not run into the root corner case
    

    这不是什么吗 应该这样做,还是不起作用 正确地


    相关: Rebase on the root and keep empty commits --root 我在这里明确避免的角落案例。它没有答案,只有一些评论建议我在这里展示的内容应该有效。另一个区别是,在另一个问题中,提交首先是空的,而在这里,它只有在解决冲突后才变为空。

    3 回复  |  直到 9 年前
        1
  •  7
  •   torek    9 年前

    这是一种bug,是由某种功能引起的。:-)

    当您运行交互式重新设置基并且它“暂停”时,实际上 ,但留下了一些文件 git rebase 意识到这毕竟是一个延续。就目前而言,这很好;你需要跑步 git rebase --continue 稍后启动新的重新设置并告诉它:

    让我们来看一个“交互式再基地”。实际上,这主要是一系列的樱桃采摘操作: pick 命令从字面上指示正在逐步淘汰的旧rebase shell脚本运行 git cherry-pick .

    好的,到目前为止没什么大不了的。但是让我们考虑一下 为什么?

    1. 或者,出现了一个问题,例如迫使停止的合并冲突。

    在案例(1)中,当您运行时 ,Git应该 不

    在案例(2)中,当您运行时 git rebase--继续 ,Git 应该 不 做出自己的承诺。

    Git可以,也可能应该,记录停止的原因,以便区分这两种情况。。。但事实并非如此。相反,它只关注 --continue .

    对于 不 -交互式重基,Git知道它只在冲突时停止,所以它知道尝试进行提交,并在没有什么可提交的情况下进行投诉。这就是 --keep-empty 或 -k git format-patch 和 git am --preserve-merges 实施原因 --继续 可以只使用相同的代码进行交互式和非交互式重新基址,但Git

    不过,对于交互式的重新基址,Git 在案例(2)中,您需要在运行之前做出自己的承诺 git rebase--继续 --继续 --继续 --保持为空 不能

    解决方法是自己动手 git commit --allow-empty 解析合并后。换句话说,使用“您可以自己提交”功能将案例(2)转换为模拟案例(1)。

        2
  •  5
  •   VonC    6 年前

    --keep-empty 选项中,我仍然希望在REBASE中存在一个空的提交,这将向我表明,如果存在的话,A将被修改。

    但显然情况并非如此:

    git rebase --keep-empty “如果另一方包含空提交(由于” does an equivalent patch exist already? “检查), .

    看见 commit 3d94616 commit 76ea235 , commit bb2ac4f (2018年3月20日) Phillip Wood ( phillipwood )
    Junio C Hamano -- gitster -- 在里面 commit d892bee

    rebase -i --keep-empty :不修剪空提交

    如果在的左侧有空提交 $upstream...HEAD --cherry-pick
    --cherry-mark 而不是 --樱桃采摘 并保留空的提交或未标记为樱桃拣选的提交。

    以及:

    rebase --keep-empty :始终使用交互式重基

    rebase --merge --保持为空 但只要忽略它,使用 隐式交互重新设置用户仍然获得重命名检测 基于合并的重新基址,但具有

    如果重新设置基 --保持为空 没有 --interactive 或 --merge 用户解决合并冲突,然后' git rebase --continue '将 失败这是因为它使用了不同的代码路径 $git_dir/rebase-apply .
    使用实现 cherry-pick --signoff


    注意:这是添加到的更大功能的一部分 git rebase
    What exactly does Git's “ rebase --preserve-merges ” do (and why?)
    具有 git --rebase-merges (最终将取代旧的 git --preserve-merges ),现在可以在其他位置重新设置提交图的整个拓扑结构的基础。


    Git 2.27(2020年第2季度),” “(再次)学会尊重” --no-keep-empty

    交互式重新基还标记以下提交: empty 在 todo .

    commit 50ed761 commit b9cbd29 commit 1b5735f (2020年4月11日) Elijah Newren ( newren )
    (合并人 Junio C Hamano-- 吉斯特 在里面 commit c7d8f69

    rebase

    报告人:布莱恩·特纳

    签字人:Elijah Newren

    d48e5e21da (“rebase(interactive backend):make--保留默认值为空”,2020-02-15,Git v2.26.0-rc0-- merge batch #8 )转弯 --保持为空

    支持提交的逻辑是:

    1. ' git commit '在创建没有覆盖标志的空提交时出错

    而不是跳到 --保持为空 唯一可用的行为。

    人们仍然可以删除开始为空的提交,就像删除任何提交一样:启动一个交互式重新基并从列表中选择他们不想要的提交。

    然而,在某些情况下,外部工具可能会创建足够多的空提交,因此将它们全部清除是很痛苦的。

    使用已存在多年的标志,为用户提供删除开始为空的提交的方法: --否保持为空

    解释 --保持为空 作为对任何先前 ,否则就要离开了 --保持为空

    这可能会导致一些轻微的奇怪,因为命令如下:

    git rebase --empty=drop --keep-empty
    git rebase --empty=keep --no-keep-empty
    

    看起来真的很奇怪,尽管感觉很好(第一个会删除变为空的提交,但保留开始为空的提交;第二个会保留变为空的提交,但删除开始为空的提交)。

    --否保持为空

        3
  •  0
  •   马哥私房菜    8 年前

    我也遇到了这个问题。

    • 3328dbe-为马(HEAD)添加hello world测试代码(14分钟前)

    当我使用cmd“git rebase-i-root-keep empty”时 没有提交“3fd2d95-init empty commit”

    所以我强制在第一行插入一行“pick 3fd2d95 init empty commit”。