简体   繁体   English

Git:如何将“合并远程跟踪分支”改造并压缩到后来的提交中?

[英]Git: How to rebase and squash “Merge remote-tracking branch” to the later commit?

I've created a pull request which has the commits as shown below. 我已经创建了一个pull请求,其提交如下所示。 However, I am required to rebase the Merge remote-tracking branch 'original/master' into avsp commit. 但是,我需要将Merge远程跟踪分支'original / master'重新定义为avsp commit。

git log output 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).

Expected git log 预期的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 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).

I tried to rebase and squash the last 2 commits into 1 so I tried 我试图将最后2次提交变为1并将其压缩为1,所以我尝试了

git rebase -i HEAD~2 git rebase -i HEAD~2

This resulted in around ~450 commits 这导致大约450次提交

  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

Now when try to pick the eb4b301a commit and squash the rest, I see this error below: 现在当尝试选择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'.

If it is not possible to rebase, is it possible to simply delete the commit from the commit history? 如果无法重新绑定,是否可以简单地从提交历史中删除提交? Would there be a side effect because of that? 会因此而产生副作用吗?

1) To perform a squash operation in an interactive rebase, you need to have a parent commit of the commit being squashed. 1)要在交互式rebase中执行压缩操作,您需要让提交的父提交被压缩。 The reason being - commit being squashed gets squashed in to the parent commit :) 原因是 - 提交被压扁被压缩到父提交:)

Hence, you can not squash the last commit as it does not have a commit to be squashed in to. 因此,你不能压缩最后一次提交,因为它没有提交被压缩到。

In your case, if you put 在你的情况下,如果你把

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

you will be able to rebase. 你将能够改变。

2) I guess you will be able to get rid of the merge commit just by performing an interactive rebase without doing any specific operation. 2)我想你可以通过执行交互式rebase而不进行任何特定操作来摆脱合并提交。 Try doing this: 试着这样做:

git rebase -i HEAD~2

It will show up 450+ commits because of the merge commit and present a list to pick/squash/delete. 由于合并提交,它将显示450多个提交,并提供一个选择/压缩/删除列表。

Do not change any operation and proceed [ESC + :wq in case of Windows OS]. 不要更改任何操作并继续[ESC +:wq,如果是Windows操作系统]。 Now once it says Successfully rebased, check git log. 现在一旦说成功重新定位,请检查git log。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM