Git:如何将"Merge remote-tracking branch"变基并压缩到后面的提交?



我创建了一个拉动请求,该请求的提交如下所示。但是,我需要将合并远程跟踪分支"原始/主"合并为AVSP commit。

git日志输出

commit eb4b301a88f02adccecdc09b82e4fc4a12656d34 (HEAD -> avsp, origin/avsp)
Author: Nikhil P <nikhilap@blah.com>
Date:   Thu May 2 20:26:45 2019 -0700
    Address some review comments
commit 0ba34d2145688c133152e7db1d8bf29f503ab34c
Merge: 5e7c1a31 beacedb0
Author: Nikhil P <nikhilap@blah.com>
Date:   Thu May 2 00:32:02 2019 -0700
    Merge remote-tracking branch 'original/master' into avsp
commit beacedb0b2b2e4ceb1b8b626b94f66ba592356a4
Author: Guy Harris <guy@alum.mit.edu>
Date:   Wed May 1 00:23:08 2019 -0700
    Remove the IPv6 payload length checks for checksumming.
    If there isn't an IPv6 payload, there isn't any TCP or UDP packet, and
    there's no TCP or UDP header to checksum, so there's no need for the
    check (it's not there for IPv4).

预期git log

commit eb4b301a88f02adccecdc09b82e4fc4a12656d34 (HEAD -> avsp, origin/avsp)
Author: Nikhil P <nikhilap@blah.com>
Date:   Thu May 2 20:26:45 2019 -0700
    Address some review comments
commit beacedb0b2b2e4ceb1b8b626b94f66ba592356a4
Author: Guy Harris <guy@alum.mit.edu>
Date:   Wed May 1 00:23:08 2019 -0700
    Remove the IPv6 payload length checks for checksumming.
    If there isn't an IPv6 payload, there isn't any TCP or UDP packet, and
    there's no TCP or UDP header to checksum, so there's no need for the
    check (it's not there for IPv4).

我试图将最后2次提交为1,所以我尝试了

git rebase -i头〜2

这导致〜450 consits

  1 pick 111e17e8 Don't use CMAKE_C_STANDARD, it doesn't work on all versions of CMake.
  2 pick 32f8eded Initialize C_ADDITIONAL_FLAGS where we start setting it.
   ** Snipped 400 more commits here ** 
451 pick beacedb0 Remove the IPv6 payload length checks for checksumming.
452 pick eb4b301a Address some review comments

现在尝试选择 eb4b301a 提交并挤压其余的时,我在下面看到此错误:

error: cannot 'squash' without a previous commit
You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
Or you can abort the rebase with 'git rebase --abort'.

如果不可能重新恢复,是否可以简单地从提交历史记录中删除该提交?因此会有副作用吗?

1(要在交互式折叠中执行壁球操作,您需要对被压缩的提交的父母提交。原因是 - 被压制到父母犯罪中:(

因此,您不能挤压最后一个提交,因为它没有被压制到的犯罪。

在您的情况下,如果您放置

451 squash beacedb0 Remove the IPv6 payload length checks for checksumming.
452 pick eb4b301a Address some review comments

您将能够反弹。

2(我想您将可以通过执行交互式反击而无需进行任何特定操作来摆脱合并提交。尝试这样做:

git rebase -i HEAD~2

它将出现450多个提交,因为合并提交并提供了一个列表以选择/supsash/delete。

请勿更改任何操作,然后继续[Windows OS的情况下[ESC :WQ]。现在,一旦它成功地重新重新恢复,请检查git log。

最新更新